I have the following xml file looks like :
<test>
<test2>
<A>206942</A>
</test2>
<test2>
<A>203405</A>
</test2>
</test>
I need to insert into sql server table
XmlNodeList dataNodes = xmlDoc.SelectNodes("/test/test2");
SqlConnection dbConnection = new SqlConnection(connectionString);
try
{
dbConnection.Open();
foreach (XmlNode node in dataNodes)
{
String A= (node.SelectSingleNode("A") != null) ? node.SelectSingleNode("A").InnerText.ToString() : string.Empty;
try
{
using (SqlCommand cmd = dbConnection.CreateCommand())
{
cmd.Parameters.AddWithValue(" @A", A);
cmd.ExecuteNonQuery();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
I try the code above and I always get the following error :
Incorrect syntax near @A Must declare the scalar variable @A
How to resolve it ?
No comments:
Post a Comment