امتیاز موضوع:
  • 0 رأی - میانگین امتیازات: 0
  • 1
  • 2
  • 3
  • 4
  • 5
radiobutton
نویسنده پیام
stringf آفلاین
كاربر دو ستاره
**

ارسال‌ها: 110
موضوع‌ها: 45
تاریخ عضویت: آذر ۱۳۹۰

تشکرها : 32
( 2 تشکر در 2 ارسال )
ارسال: #1
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 آفلاین
كاربر دو ستاره
**

ارسال‌ها: 110
موضوع‌ها: 45
تاریخ عضویت: آذر ۱۳۹۰

تشکرها : 32
( 2 تشکر در 2 ارسال )
ارسال: #2
RE: radiobutton
(۲۵-تير-۱۳۹۱, ۱۱:۱۸:۰۷)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);


        }
    }
}
۲۶-تير-۱۳۹۱, ۱۶:۱۰:۳۷
ارسال‌ها
پاسخ


پرش به انجمن:


کاربرانِ درحال بازدید از این موضوع: 1 مهمان

صفحه‌ی تماس | IranVig | بازگشت به بالا | | بایگانی | پیوند سایتی RSS