i have problem with database connectivity sql with c#
Database connectivity
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Shivanand ArurRank #920 · 2.3K reputationPosted Dec 29, 2013, 6:49 PM EST
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 29, 2013, 6:58 PM EST
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();
}
}
}
Pradeep Patel46 reputationPosted Dec 29, 2013, 6:58 PM EST
post your code