How to connect to SQL Database with C#?
1) connects fine, other times fails connect. using integrated security / windows login.
2) trying pass select statement (which works sql server management studio), doesn't seem work in program. code doesn't appear really...
3) when use code generated vs, loads information datagridview, want filter using select statement.
here code generated vs:
private void form1_load(object sender, eventargs e)
{
this.collectiontableadapter.fill(this.dbdataset.collection);
}
here code:
private void form1_load(object sender, eventargs e)
{
//connect database collections table
sqlconnection thisconnection = new sqlconnection(@"server=(local)\sqlexpress;integrated security=true;" +
"database=db");
//create dataadapter object
sqldataadapter thisadapter = new sqldataadapter("select number [#], image1 [image], title1 [title], issue1 [issue] table1 tab = 'tab1'", thisconnection);
//create dataset contain related data tables, rows, , columns
dataset thisdataset = new dataset();
//fill dataset using query defined dataadapter
thisadapter.fill(thisdataset, "collection");
foreach (datarow therow in thisdataset.tables["collection"].rows)
{
console.writeline(therow["number"] + "\t" +
therow["image1"] + "\t" +
therow["title1"] + "\t" +
therow["issue1"]);
}
//close connection
thisconnection.close();
}
the first thing need check connection string....
refer : http://www.connectionstrings.com/?carrier=sqlserver2005
and check user /login credential
madhu
SQL Server > SQL Server Tools
Comments
Post a Comment