Hi,
The code looks pretty ok, its strange that the row aint being inserted in the table.
However, u might want to debug by catching an int variable as return when the insert statement takes place and alert a message when the return value is greater than 0.
have a look at the below code:
public int InsertName(string xname)
{
int ret;
SqlCommand cmd = new SqlCommand("Insert into Sample.dbo.tblName values('" + xname + "')", xconn);
try
{
xconn.Open();
ret = cmd.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
xconn.Close();
}
return ret;
}
and on the click of a button or any other event the code will be like below:
private void btnAdd_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(txtName.Text))
{
DataBaseLayer obj = new DataBaseLayer();
int param=obj.InsertName(txtName.Text);
if (param > 0)
{
MessageBox.Show("your name has been saved..you can now go to the main page");
}
NewForm obj2 = new NewForm();
obj2.Show();
}
}
Try to debug like this, you might find whether the insert statement is actually executing or not.
Hope it helps.
Regards
Anurag