Simon Cripps
asked on
C# .net connection string
Hi, I have created several sites in VB, but now need to create / convert a few more to C#.
I want to link a grid view to a dataset that I have, I have done it many times in vb but never in c#.
I have set up a data connection string in the web config which works as I have tested it against an SQLdatasource component embeded into the page.
I want to do this more programatically in the source so I have taken some of my VB script and placed it trough a convertor. and got out the other side the script attached. However I get an issue
"Non-invocable member 'System.Configuration.Conf igurationM anager.Con nectionStr ings' cannot be used like a method." when I try to bind to the gridview.
Any suggestions
I want to link a grid view to a dataset that I have, I have done it many times in vb but never in c#.
I have set up a data connection string in the web config which works as I have tested it against an SQLdatasource component embeded into the page.
I want to do this more programatically in the source so I have taken some of my VB script and placed it trough a convertor. and got out the other side the script attached. However I get an issue
"Non-invocable member 'System.Configuration.Conf
Any suggestions
protected void Gridview1_Set()
{
string connStr = ConfigurationManager.ConnectionStrings("acVitaConnectionString").ConnectionString;
SqlConnection con = new SqlConnection(connStr);
SqlCommand SQLCmd = new SqlCommand("SPTopProducts", con);
SQLCmd.CommandType = CommandType.StoredProcedure;
try
{
SQLCmd.Connection.Open();
GridView1.DataSource = SQLCmd.ExecuteReader();
GridView1.DataBind();
SQLCmd.Connection.Close();
SQLCmd.Connection.Dispose();
}
catch (Exception ex)
{
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
did the job many thanks
string connStr = ConfigurationSettings.AppS