c# - Getting sql connection string from web.config file -
I'm learning to write from a textbox into a database with the click of a button. I have specified the connection string in my NorthWind Database in my This is what I have tried to do. I get tooltip error for SqlConnection sql = new SqlConnection (constring); As P> There are some invalid arguments in System.data.SqlClient.Sqlconnection.Sqlconnection (string). I Like this That's because the collection is a collection of objects, but if the manufacturer expects a Try it instead. web.config file. Although I am not able to use the connection string behind my code.
Protected Zero Bottom_click (Object Sender, EventArgse E) {System.configuration.Configuration rootwebconfig = System.Web.Configuration.WebConfigurationManager OpenWebConfiguration ("/ Mohtisham"); System Configuration. Connecting string setting; Constring = rootwebconfig.ConnectionStrings.ConnectionStrings ["northwindconnect"]; SqlConnection sql = new SqlConnection (constring); Sql.Open (); SqlCommand comm = new SqlCommand ("Insert values in the categories (category name) ('+ + tb_database.Text +"' '' ', sql); comm.ExecuteNonQuery (); sql.Close ();}
web. Want to load the connection string from
constring
string parameter, then you can not do the same with just
constring .
SqlConnection sql = New SqlConnection (constring.ConnectionString);
Comments
Post a Comment