how to insert variable values in SQL server using INSERT INTO statement?
-
i want to insert values (into database table) which are calculated from an expression and is stored in a variable, in INSERT INTO statement, how can i do this? i m doing this in VC++6 MFC using ODBC constant values goes perfectally in database<
What you have tried about to insert value you have no mention whatever, You can easily insert value into your database table by using
Insert into tablename values(your value depend upon table column data type)
-
i want to insert values (into database table) which are calculated from an expression and is stored in a variable, in INSERT INTO statement, how can i do this? i m doing this in VC++6 MFC using ODBC constant values goes perfectally in database<
Use parameters.
-
Use parameters.
-
for example here is some part of my code: string str="Birthday"; i have to insert this str variable using: INTERT into mytable VALUES(str) ; how can i insert this??? n i dont know how to use parameters...plz tell me some very easy way to do this...:(
It partly depends on what language you host your SQL in, also on which database system you use. INSERT INTO table (field0, field1 ...) VALUES (@Param0, @Param1 ... ) Then create parameters. Then, as you loop through the data to insert, set the parameters and execute the statement.
-
for example here is some part of my code: string str="Birthday"; i have to insert this str variable using: INTERT into mytable VALUES(str) ; how can i insert this??? n i dont know how to use parameters...plz tell me some very easy way to do this...:(
I let you from the beginning step by step to insert data into table Create a connection by using SqlConnection class as
SqlConnection con = new SqlConnection("connectionString") // Connectionstring is responsible to store info to connect database.
then, you need to create Command object by SqlCommand Class as
string str = INTERT into mytable VALUES('"+str+"');
SqlCommand cmd = new SqlCommand(str,con); // str is responsible to hold you insert command and con is object of connectionthen you need to execute query by using ExecuteNonQuery Method as
cmd.ExecuteNonQuery();
This is easiest way to insert data into table. Hope it will work for you.. :)
-
for example here is some part of my code: string str="Birthday"; i have to insert this str variable using: INTERT into mytable VALUES(str) ; how can i insert this??? n i dont know how to use parameters...plz tell me some very easy way to do this...:(
if you don;t want to use parameter then simple make Connction and Command and Execute your command it will save your data.
-
I let you from the beginning step by step to insert data into table Create a connection by using SqlConnection class as
SqlConnection con = new SqlConnection("connectionString") // Connectionstring is responsible to store info to connect database.
then, you need to create Command object by SqlCommand Class as
string str = INTERT into mytable VALUES('"+str+"');
SqlCommand cmd = new SqlCommand(str,con); // str is responsible to hold you insert command and con is object of connectionthen you need to execute query by using ExecuteNonQuery Method as
cmd.ExecuteNonQuery();
This is easiest way to insert data into table. Hope it will work for you.. :)
-
if you don;t want to use parameter then simple make Connction and Command and Execute your command it will save your data.
Please don't give people bad advice like this. You've basically just advised the poster that they should leave themselves wide open to a SQL Injection attack, and that's not cool.
I have CDO, it's OCD with the letters in the right order; just as they ruddy well should be
Forgive your enemies - it messes with their heads