Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
cmd = new SqlCommand(candintrest, cn);
 cmd.CommandText = candintrest;
 int interestid = (int)cmd.ExecuteScalar();    *****error specify on this line***

Error Occure:-
C#
System.Data.SqlClient.SqlException: Incorrect syntax near ',' 

plz try to solve it.
Posted
Updated 3-Jun-12 19:34pm
v2
Comments
Prasad_Kulkarni 4-Jun-12 1:34am    
Can you provide your sql query??

I think In your quary has error once check your quary(candintrest)

ex:For Insert Quary
SQL
create procedure like
Create PROCEDURE dbo.StoredProcedure1(@id int,@name varchar(50),@addr varchar(50))
	/*
	(
	@parameter1 int = 5,
	@parameter2 datatype OUTPUT
	)
	*/
AS
begin
insert into sample (id,name,address) values(@id,@name,@addr)
	/* SET NOCOUNT ON */
	end


in code behind:
VB
con = New SqlConnection(ConfigurationManager.ConnectionStrings("con").ConnectionString)  
        cmd = New SqlCommand()
        If con.State = ConnectionState.Closed Then
            con.Open()
        End If
        cmd.Connection = con
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "StoredProcedure1"
        cmd.Parameters.AddWithValue("@id", TextBox1.Text)
        cmd.Parameters.AddWithValue("@name", TextBox2.Text)
        cmd.Parameters.AddWithValue("@addr", TextBox3.Text)


        Dim i As Integer

        i = cmd.ExecuteNonQuery()
        If (i >= 1) Then
            Response.Write("sucess")
        Else
            Response.Write("Fail")
        End If
        con.Close()
 
Share this answer
 
v4
Hello This will be helpful to you..........

Just keep Quotes
C#
cmd = new SqlCommand("candintrest", cn);
 
Share this answer
 
v2
Please check all ' and , and " and + symbols in your query
 
Share this answer
 
Int32 count = Convert.ToInt32(cmd.ExecuteScalar());
 
Share this answer
 
VB
con = New SqlConnection(ConfigurationManager.ConnectionStrings("con").ConnectionString)
        cmd = New SqlCommand()
        If con.State = ConnectionState.Closed Then
            con.Open()
        End If
        cmd.Connection = con
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "StoredProcedure1"
        cmd.Parameters.AddWithValue("@id", TextBox1.Text)
        cmd.Parameters.AddWithValue("@name", TextBox2.Text)
        cmd.Parameters.AddWithValue("@addr", TextBox3.Text)


        Dim i As Integer

        // or Int32 count = Convert.ToInt32(cmd.ExecuteScalar());
        i = cmd.ExecuteNonQuery()
        If (i >= 1) Then
            Response.Write("sucess")
        Else
            Response.Write("Fail")
        End If
        con.Close()
 
Share this answer
 
Hello
please specify ur canduntrest (i.e Sql which is causing problem) so that i will guide properly
 
Share this answer
 
Comments
Rahul Rajat Singh 5-Jun-12 1:41am    
this is not a solution. use the comments section for such questions.
first check what have you written in insert query. in place of cmd.ExecuteScalar use cmd.ExecuteNonQuery. i think after that your problem should be solved
 
Share this answer
 
Comments
Member 9027483 4-Jun-12 1:23am    
there is cmd.ExecuteNonQuery is used...so what can i do???
Prosan 5-Jun-12 1:55am    
please provide your insert query. error in your insert query.

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