i m new to .net and db connectivity in .net using sql server....
i want to insert values from into a db test1 from a function register(); where i will pass values the function register
will this syntax work...
public void register(int mc,int pt)
{
SqlConnection conn = new SqlConnection(@ "Data Source=.\SQLEXP RESS;AttachDbFi lename=C:\Inetp ub\wwwroot\WebS ite1\App_Data\t est.mdf;Integra ted Security=True;U ser Instance=True") ;
conn.Open();
SqlCommand command = new SqlCommand("ins ert into test1 values(mc,pt)", conn);
command.Execute NonQuery();
conn.Close();
}
b"cos this syntax gives a error:
System.Data.Sql Client.SqlExcep tion: The name "mc&quo t; is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
at System.Data.Sql Client.SqlConne ction.OnError(S qlException exception, Boolean breakConnection )
at System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion exception, Boolean breakConnection )
at System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct stateObj)
at System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleR esultSet bulkCopyHandler , TdsParserStateO bject stateObj)
at System.Data.Sql Client.SqlComma nd.RunExecuteNo nQueryTds(Strin g methodName, Boolean async)
at System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe)
at System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery()
at FirstService.re gister(Int32 mc, Int32 pt)
is this error...b"cos of sql insert in an ways...if it is wht shld be the correct way to fire the querry...
i want to insert values from into a db test1 from a function register(); where i will pass values the function register
will this syntax work...
public void register(int mc,int pt)
{
SqlConnection conn = new SqlConnection(@ "Data Source=.\SQLEXP RESS;AttachDbFi lename=C:\Inetp ub\wwwroot\WebS ite1\App_Data\t est.mdf;Integra ted Security=True;U ser Instance=True") ;
conn.Open();
SqlCommand command = new SqlCommand("ins ert into test1 values(mc,pt)", conn);
command.Execute NonQuery();
conn.Close();
}
b"cos this syntax gives a error:
System.Data.Sql Client.SqlExcep tion: The name "mc&quo t; is not permitted in this context. Valid expressions are constants, constant expressions, and (in some contexts) variables. Column names are not permitted.
at System.Data.Sql Client.SqlConne ction.OnError(S qlException exception, Boolean breakConnection )
at System.Data.Sql Client.SqlInter nalConnection.O nError(SqlExcep tion exception, Boolean breakConnection )
at System.Data.Sql Client.TdsParse r.ThrowExceptio nAndWarning(Tds ParserStateObje ct stateObj)
at System.Data.Sql Client.TdsParse r.Run(RunBehavi or runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleR esultSet bulkCopyHandler , TdsParserStateO bject stateObj)
at System.Data.Sql Client.SqlComma nd.RunExecuteNo nQueryTds(Strin g methodName, Boolean async)
at System.Data.Sql Client.SqlComma nd.InternalExec uteNonQuery(DbA syncResult result, String methodName, Boolean sendToPipe)
at System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery()
at FirstService.re gister(Int32 mc, Int32 pt)
is this error...b"cos of sql insert in an ways...if it is wht shld be the correct way to fire the querry...
Comment