with this code am trying to update my table . but am not getting idea how to execute it.
at int UserId; am getting error
public void ServiceInfo(int id)
{
string conn = Connection.ConnectionString;
SqlConnection mycon = new SqlConnection(conn);
mycon.Open();
foreach (DataGridViewRow row in dataGridView1.Rows)
{
string DisplayName = row.Cells[3].Value.ToString();
string ServiceName = row.Cells[4].Value.ToString();
string Status = row.Cells[5].Value.ToString();
string ServiceType = row.Cells[6].Value.ToString();
int UserId;
SqlCommand com = new SqlCommand(conn, mycon);
if (UpdateServices(UserId))
{
com.CommandText = "insert into ServiceInfo(DisplayName,ServiceName,Status,ServiceType,UserId)values('" + DisplayName + "','" + ServiceName + "','" + Status + "','" + ServiceType + "'," + id + ")";
}
else
{
com.CommandText = "UPDATE ServiceInfo SET" + " DisplayName='" + DisplayName + "',ServiceName='" + ServiceName + "',Status='" + ServiceType + "',ServiceType='" + ServiceType + "',UserId='"+UserId +"' Where UserId='" + UserId + "'";
}
com.ExecuteNonQuery();
com.Parameters.Clear();
com.Dispose();
}
mycon.Close();
mycon.Dispose();
}
Help me in solving this query
thanks
sam.198979