i have problem with database connectivity sql with c#
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pradeep PatelPosted Dec 29, 2013, 11:58 PM
post your code
Satyapriya NayakPosted Dec 29, 2013, 11:58 PM
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.SqlClient;
namespace listbox
{
public partial class Form1 : Form
{
SqlConnection con = new SqlConnection(@"server = HOME-SAT/SQLEXPRESS;data source = .; initial catalog = test; user id=sa;pwd =pintu ;integrated security = SSPI");
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
DataTable dt;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
listboxbind();
}
private void listboxbind()
{
con.Open();
str = "select * from employee";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "employee");
dt = ds.Tables["employee"];
listBox1.DisplayMember = "empid";
listBox1.ValueMember = "empname";
listBox1.DataSource = ds.Tables["employee"];
con.Close();
}
}
}
Shivanand ArurPosted Dec 29, 2013, 11:49 PM