Problem with SQL table read and write
I would like help with using ADO connection to read records from SQL table, make cahnges to just user name column and reinsert record as new using stored procedures. Here is a sample code:
sqlConnention rCon = new sqlconnection ("UID......);
rCon.Open();
strSQL = "Select statement"
SqlCommand cmd = new SqlCommand(strlSQL, rCon);
SqlDataReader reader = null;
Sql Connection writeCon = new SqlConnection( "UID+....).
SqlCommand oCom
SqlParameter oParameter
str2SQL = "AddNew ";
oCom = new SqlCommand(str2SQL, writeCon);
oCom.CommandType = CommandType.StoredProcedure;
reader = cmd.ExecuteReader();
while (reader.Read())
{
areaname.Text = reader["name"].ToString();
oCom.Parameter.Add("@name", SqlDbType.VarChar, 25).Value = newname.Text;
oCom.Parameter.Add("areaname", SqlDbType.Varchar, 6).Value =areaname.Text;
}
try
{
if (Connection.Sate == Connection.Closed)
{
writeCon.Open();
}
oCom.ExecuteNonQuery
}
Catch(Exception, myExp)
{
throw myExp;
}
}
I cannot get any record to write. Help.
|