ايران ويج

نسخه‌ی کامل: radiobutton
شما در حال مشاهده‌ی نسخه‌ی متنی این صفحه می‌باشید. مشاهده‌ی نسخه‌ی کامل با قالب بندی مناسب.
سلام
این کد چه مشکلی داره که search دفترچه تلفن وقتی روی دکمه search کلیک میکنیم جوابی نمی ده؟
فرم تشکیل شده از دکمه search و یک datagridviewو یک textbox
وdatabaseهم دارای name,family,tell,id می باشد
کد:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            dbConnect dbc = new dbConnect();
            string s = " ";
            if (radioButton1.Checked == true)
            {
                s = string.Format("select * from tell where name='{0}%'", textBox1.Text);
        
            }
            else
            {
                if (radioButton2.Checked == true)
                {
                    s = string.Format("select * from tell where family='{0}%'", textBox1.Text);
                    
                }
                else
                {
                    if (radioButton3.Checked == true)
                    {
                        s = string.Format("select * from tell where tell='{0}%'", textBox1.Text);
                        
                    }
                }dataGridView1.DataSource = dbc.selectcmd(s);
                
                if (dbc.lasterror != null)
                {
                    MessageBox.Show(dbc.lasterror);
                }
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            // TODO: This line of code loads data into the 'dbsearchDataSet.tell' table. You can move, or remove it, as needed.
            this.tellTableAdapter.Fill(this.dbsearchDataSet.tell);

        }
        }
    }
(۲۵-تير-۱۳۹۱, ۱۱:۱۸:۰۷)stringf نوشته است: [ -> ]سلام
این کد چه مشکلی داره که search دفترچه تلفن وقتی روی دکمه search کلیک میکنیم جوابی نمی ده؟
فرم تشکیل شده از دکمه search و یک datagridviewو یک textbox
وdatabaseهم دارای name,family,tell,id می باشد
کد:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
dbConnect dbc = new dbConnect();
string s = " ";
if (radioButton1.Checked == true)
{
s = string.Format("select * from tell where name='{0}%'", textBox1.Text);

}
else
{
if (radioButton2.Checked == true)
{
s = string.Format("select * from tell where family='{0}%'", textBox1.Text);

}
else
{
if (radioButton3.Checked == true)
{
s = string.Format("select * from tell where tell='{0}%'", textBox1.Text);

}
}dataGridView1.DataSource = dbc.selectcmd(s);

if (dbc.lasterror != null)
{
MessageBox.Show(dbc.lasterror);
}
}
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dbsearchDataSet.tell' table. You can move, or remove it, as needed.
this.tellTableAdapter.Fill(this.dbsearchDataSet.tell);

}
}
}


سلام
برای اینکه برنامه جواب بده باید ...else ها را پاک کنیم!!!
کد:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;

namespace WindowsFormsApplication5
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string str = "";

        private void button1_Click(object sender, EventArgs e)
        {
            dbConnect d = new dbConnect();
            if (radioButton1.Checked == true)
            {
                str = string.Format("Select * from tell where name=N'{0}'", textBox1.Text);
            }
            if (radioButton2.Checked == true)
            {
                str = string.Format("Select * from tell where family=N'{0}'", textBox1.Text);
            }
            if (radioButton3.Checked == true)
            {
                str = string.Format("Select * from tell where   tell=N'{0}'", textBox1.Text);
            }

            dataGridView1.DataSource = d.selectcmd(str);


        }
    }
}