Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
below is my insert statement but its not inserting the values
any thing wrong in the statement

insert_query = "insert into ##Mytemp(Col1,Col2,Col3) values(" + char_temp + "," +int_temp + "," + tinyint_temp + ");";


Thanks Inadvance
Posted
Updated 3-Jan-12 3:11am
Comments
Amir Mahfoozi 3-Jan-12 8:45am    
How do you know that it wasn't inserted. Maybe its automatically removed because of your disconnection by ADO.NET .

Try
insert_query = "insert into Mytemp(Col1,Col2,Col3) values(" + char_temp + "," +int_temp + "," + tinyint_temp + ")";

but it should be better if you use parametrized to remove SQl injection in your application.
Using parameterized SQL queries[^]
Check Performance Implications of Parameterized Queries[^]
 
Share this answer
 
Comments
pradeep manne 3-Jan-12 8:21am    
hi,
thanks for the reply,
i have changed the statement but its not working and also am inserting into a temp table so am using ##
RaviRanjanKr 3-Jan-12 8:37am    
what error are yo getting ?
pradeep manne 3-Jan-12 8:39am    
invalid object name Mytemp
pradeep manne 3-Jan-12 8:56am    
hi, this statement is working but am getting error like

The identifier that starts with '
and exists XXXXXX
Where XXXXX' is too long. Maximum length is 128.
If the statement is inside a stored procedure and you're creating the global temporary table first, it should be ok. If you're trying to run the statement from client side, the insert is valid only within a single batch and you must create the table in the same batch.

Also you're using global temporary table which is visible to all sessions. Is this what you really want to do? Using table typed variables is a preferred way over temporary tables.
 
Share this answer
 
I dont think you can make a temp table in SQL the way you are thinking, since it only exists within the scope of the query/stored procedure that creates it.

Itz recommended to create a Table in SQL to put this into.
 
Share this answer
 
C#
insert_query = "insert into ##Mytemp(Col1,Col2,Col3) values('" + char_temp + "','" +int_temp + "','" + tinyint_temp + "')";

hope this is helps you



Regards
R.dhanabal
 
Share this answer
 
v2
Comments
pradeep manne 3-Jan-12 8:24am    
hi,
thanks for the quick reply
but still its not working
RaviRanjanKr 3-Jan-12 8:39am    
[Edited]Code is wrapped in pre tag[/Edited]
pradeep manne 3-Jan-12 8:58am    
wat does it mean

The identifier that starts with '
and exists XXXXXX
Where XXXXX' is too long. Maximum length is 128.
remove "values" keyword from your query
 
Share this answer
 
please use below
insert_query = "insert into ##Mytemp(Col1,Col2,Col3) values('" + char_temp + "','" +int_temp + "','" + tinyint_temp + "');";
 
Share this answer
 
v2
Comments
RaviRanjanKr 3-Jan-12 8:40am    
[Edited]pre tag is removed from normal texts[/Edited]
try this or follow this ....
C#
string str="insert into tablename (column1,column2,column3,column4,column5,column6,column7)values('"+txt1+"','"+txt2.text+"','"+txt3.text+"','"+txt.text+"','"+txt.text+"','"+txt.text+"'"

sqlcommmnad cmd=new sql command(str,con);

cmd.exicutenonquery();

con. close();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900