im trying to read from a text file and use the id's inside the text file to update the status of the id's in a table to ok or whatever.
it reads the text file successfully and at the point to updating it throws the error
String or binary data would be truncated.
the id's in the text file looks like this:
1606873,1412393,1588593,1481673,1351153,1422153,1790433,1587033,1582593,1474233,1398953,1704553,1631313,1576513,1757113,1360193,1648393,1455473,1517753,1773633,1428153,1691553,1795793,1805113,1572513,1397353,1447473,1533393,1374273,1530353,1368233,1667313,1431793,1396953,1720633,1648633,1483753,1573993,1499673,1768273,1541193,1556673,1555793
alot more than this anyway.
What I have tried:
private void btnTest_Click(object sender, EventArgs e)
{
ReadFromTextFile();
}
public void ReadFromTextFile()
{
StreamReader str = new StreamReader(@"C:\midMonth30072016\AppLog_Test.txt");
while ((line = str.ReadLine()) != null)
{
updatestatus(line);
}
}
public void updatestatus(string da)
{
try
{
if (con.State != ConnectionState.Open)
{
con.Open();
}
SqlCommand cmd = new SqlCommand();
string query = "update tblMidMonthold set Status='processed' where ID in ( @data )";
SqlCommand sqlCmd = new SqlCommand(query, con);
sqlCmd.Parameters.AddWithValue("@data", line);
SqlDataReader dr = sqlCmd.ExecuteReader();
}
catch (Exception)
{
throw;
}
}