hi,
i am new in C# , i have 2 text boxes in which the user will enter the department and name,
1- I want the application to retrict the user to only enter letters not numbers . This is my following code:
public string Directorates_Insert(string Directorate_Name, string Directorate_Head)
{
SqlConnection con = new SqlConnection();
SqlCommand com = new SqlCommand();
try
{
con.ConnectionString = conString;
con.Open();
com.Connection = con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "Directorates_Insert";
com.Parameters.AddWithValue("@Directorate_Name", Directorate_Name);
com.Parameters.AddWithValue("@Directorate_Head", Directorate_Head);
com.ExecuteNonQuery();
return "0";
}
catch(Exception ex)
{
return ex.Message;
}
finally
{
con.Close();
// da.Dispose();
com.Dispose();
con.Dispose();
}
}
}
public partial class Parts_Directorate : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_save_Click(object sender, EventArgs e)
{
btn_save.Enabled = false;
lookups insert = new lookups();
string result = insert.Directorates_Insert(txt_DirName.Text.Trim(), txt_DirHead.Text.Trim());
if (result == "0")
{
lbl_msg.ForeColor = System.Drawing.Color.Blue;
lbl_msg.Text = "Successful";
}
else
{
lbl_msg.ForeColor = System.Drawing.Color.Red;
lbl_msg.Text = result;
}
btn_save.Enabled = true;
}
2- How can i put a grid view to view the records he entered?
public DataSet Directorates_GetAll()
{
SqlConnection con = new SqlConnection();
SqlCommand com = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataSet ds = new DataSet();
try
{
con.ConnectionString = conString;
con.Open();
com.Connection = con;
com.CommandType = CommandType.StoredProcedure;
com.CommandText = "Directorates_GetAll";
da.SelectCommand = com;
com.Parameters.AddWithValue("@ID", DBNull.Value);
com.ExecuteNonQuery();
da.Fill(ds);
return ds;
}
catch
{
return ds;
}
finally
{
con.Close();
ds.Dispose();
da.Dispose();
com.Dispose();
con.Dispose();
}
}
Thank you