Hello all. I wasn't sure if I should post this here or under DB?

I'm a PHP user that is new to C#/ASP.NET/MS SQL.

I have a table with rows of string values (not sure why they were made strings as they are numbers but thats what they are).

I have a variable TheNumber that is Int. I am trying to convert that to string and insert it into the DB but I keep getting the type clash error. DBConnection is previously defined with the correct connection string.

Here is the code (the error is on the 2nd to last line that starts WriteToDB:

DBConnection.Open();
	   string TempTheNumber = Convert.ToString(TheNumber);
	   String MyString = @"INSERT INTO assignedaccountnums VALUES(" + TempTheNumber + ")";	   
	   SqlCommand WriteToDB = new SqlCommand(MyString, DBConnection);
	   WriteToDB.ExecuteNonQuery();					
	   DBConnection.Close();

Any help would be appreciated!

Does it count if you finally figure out your own problem? :-)

This:

String MyString = @"INSERT INTO assignedaccountnums VALUES(" + TempTheNumber + ")";

Should have been this:

String MyString = @"INSERT INTO assignedaccountnums(accountnum) VALUES('" + TempTheNumber + "')";

-Chris

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.