Data Type Error JS & SQL Code

J

J2tehk

I am currently trying to pull the MAX value from a primary key in a table and
then adding it by 1. That number is then inserted back into the table for a
new record.

Got a problem with the code below.

I can pull the max value from the primary key in the table and now am adding
1 to it. It seems to be trying to send a varchar to the database field, which
is an int. I’m getting the Error: Conversion failed when converting varchar
“undefine†to an int.

var sSqlMax = "Select MAX(Add_Change_Req_Num) from dbo.Add_Change_Network";

var oConn = new ActiveXObject("ADODB.Connection");
oConn.ConnectionString = XDocument.QueryAdapter.Connection;
oConn.ConnectionTimeout = XDocument.QueryAdapter.Timeout; oConn.Open();

// Gets MAX value from the table’s primary key and adds 1

var req_num_add = oConn.Execute(sSqlMax);
var new_add = req_num_add + 1;

var sSqlQuery = "Insert into dbo.Add_Change_Network (Add_Change_Req_Num)
values ('"+ new_add.text +"')";

oConn.Execute(sSqlQuery);
oConn.Close();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top