I wanted to insert data to microsoft access using c# and need to use class.
I've tried removing some textbox and look for some error and I feel that there might be some mistake in IF condition.
private void registerbutton_Click(object sender, EventArgs e)
{
-- CLASS --
RegStudent reg = new RegStudent();
reg.stdfname = fnametextbox.Text;
reg.stdlname = lnametextbox.Text;
reg.username = usernametextbox.Text;
reg.password = passwordtextbox.Text;
reg.dob = dobtextbox.Text;
reg.city = citytextbox.Text;
reg.state = statetextbox.Text;
reg.email = emailtextbox.Text;
reg.phoneno = ctcnotextbox.Text;
reg.phoneno2 = ctcnotextbox2.Text;
reg.course = coursetextbox.Text;
reg.emergencyname = emergencynametextbox.Text;
reg.emergencyphoneno = emergencynumbertextbox.Text;
reg.registerdate = registerdatetextbox.Text;
if (tptextbox.Text != "" && fnametextbox.Text != "" && lnametextbox.Text != "" && dobtextbox.Text != "" && usernametextbox.Text != "" && passwordtextbox.Text != "" && citytextbox.Text != "" && statetextbox.Text != "" && registerdatetextbox.Text != "" && emailtextbox.Text != "" && ctcnotextbox.Text != "" && ctcnotextbox2.Text != "" && coursetextbox.Text != "" && emergencynametextbox.Text != "" && emergencynumbertextbox.Text != "")
{
registerconnection.Open();
OleDbCommand insert = new OleDbCommand();
insert.Connection = registerconnection;
insert.CommandText = "Insert into StudentDatabase values (" + reg.stdfname + "','" + reg.stdlname + "','" + reg.username + "','" + reg.password + "','" + reg.dob + "','" + reg.city + "','" + reg.state + "','" + reg.email + "','" + reg.phoneno + "','" + reg.phoneno2 + "','" + reg.course + "','" + reg.emergencyname + "','" + reg.emergencyphoneno + ");";
insert.CommandType = CommandType.Text;
insert.Connection = registerconnection;
insert.ExecuteNonQuery();
MessageBox.Show("Data Have Been Registered.");
}
else
{
MessageBox.Show("error");
}
}
I expected that the output will be that the data will be saved.
Related
private void button1_Click(object sender, EventArgs e)
{
try
{
if (transaction_idTextBox.Text == "" || lastnameTextBox.Text == "" || firstnameTextBox.Text == "" || middlenameTextBox.Text == "" || txtYear.Text == "" || txtDoI.Text == "" || txtPoI.Text == "" || txtAddress.Text == "" || CB_Sex.Text == "" || txtCS.Text == "" || txtDoB.Text == "" || txtPoB.Text == "" || txtAmount.Text == "")
{
MessageBox.Show("All Fields Are Compulsory");
}
else
{
SqlCommand cmdinsert = new SqlCommand("Insert into [Transaction] values( ' " + transaction_idTextBox.Text + " ','" + lastnameTextBox.Text + "','" + firstnameTextBox.Text + " ','" + middlenameTextBox.Text + "','" + txtYear.Text + "','" + txtDoI.Text + "','" + txtPoI.Text + "','" + txtAddress.Text + "','" + CB_Sex.Text + "','" + txtCS.Text + "','" + txtDoB.Text + "','" + txtPoI.Text + "','" + txtAmount.Text + "' )", con);
con.Open();
cmdinsert.CommandType = CommandType.Text;
cmdinsert.ExecuteNonQuery();
MessageBox.Show("Data Added");
transactionDataGridView.Update();
transactionDataGridView.Refresh();
transaction_idTextBox.Text = "";
lastnameTextBox.Text = "";
firstnameTextBox.Text = "";
middlenameTextBox.Text = "";
txtYear.Text = "";
txtDoI.Text = "";
txtPoI.Text = "";
txtAddress.Text = "";
CB_Sex.Text = "";
txtCS.Text = "";
txtDoB.Text = "";
txtPoB.Text = "";
txtAmount.Text = "";
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}
}
For first : Add "LoadData();" at the end of Your code
Secondly add this to populate DataGridView:
public void LoadDataEQ()
{
DataTable AllDataTable = new DataTable();
string SqlCommand = "SELECT * FROM Transaction";
SqlDataAdapter SQLDA = new SqlDataAdapter(SqlCommand , con);
SQLDA.Fill(AllDataTable);
SQLDA.Dispose();
dataGridView1.DataSource = AllDataTable;
}
I have a web form,asp.net, to save specific information into my local database in Visual Studio. Some of this web form components are html components.
After clicking an "add" button, which is as asp.net button, the data is saved successfully into the database, but when I look to my database table, it shows me "System.Web.UI.HtmlControls.HtmlInputText" in some fields as shown in the picture below:
What confuses me is that I don't know why some values are saves correctly and the others not ! the eventName, EventDuration, EventAdmission, EventWebsite and EventVenue are all html textboxes .. and as seen in the image above for all of these fields the saved value is "System.Web.UI.HtmlControls.HtmlInputText" while the EventVenue value is saved correctly!! even though the codes are the same .. see the example below:
<div class="6u$ 12u$(small)">
<label for="website">Website</label>
<input type="text" id="website" name="website" runat="server" />
</div>
<div class="6u$ 12u$(small)">
<label for="venue">Venue</label>
<input type="text" id="venue" name="venue" runat="server" />
And here is my source code:
protected void addbtn_Click(object sender, EventArgs e)
{
string latitude = "";
string longitude = "";
string imagesArr = null;
bool fields = false;
string eventname = Request.Form["name"].ToString();
string disc = Request.Form["TextArea3"].ToString();
string startDate = DropDownList1.Text + "/" + category.Value + "/" + DropDownList2.Text;
string endDate = DropDownList4.Text + "/" + days.Value + "/" + DropDownList5.Text;
string eventduration = Request.Form["duration"].ToString()
string eventadmission = admission.Value;
string categ = DropDownList3.Text;
string contact = Request.Form["TextArea4"].ToString();
string eventwebsite = website.Value;
string location = venue.Value;
country.Disabled = true;
string eventcountry = Request.Form["country"].ToString();
if (Session["Latitude"].ToString() == null && Session["Longitude"].ToString() == null)
{
latitude = "";
longitude = "";
}
else if (Session["Latitude"].ToString() != null && Session["Longitude"].ToString() != null)
{
latitude = Session["Latitude"].ToString();
longitude = Session["Longitude"].ToString();
}
if (Session["ImagesArray"].ToString() != null)
{
imagesArr = Session["ImagesArray"].ToString();
}
if (DropDownList2.Text.Equals("Year") || DropDownList1.Text.Equals("Month") || category.Value.Equals("Day") || DropDownList5.Text.Equals("Year") || DropDownList4.Text.Equals("Month") || days.Value.Equals("Day") || name == null || disc == null || duration == null || admission == null || categ == null || contact == null || website == null || location == null)
{
fields = true;
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' Make sure to enter all the required data')", true);
}
else { fields = false; }
if (fields == false)
{
command.CommandText = "INSERT INTO EventsEnglish(EventName,EventDescription,EventStartDate,EventEndDate,EventDuration, EventAdmission, EventCategory, EventContact, EventWebsite, EventVenue, EventMapLatitude, EventMapLongitude, CountryName, EventImages) values(N'" + name + "', N'" + disc + "',N'" + startDate + "',N'" + endDate + "',N'" + duration + "',N'" + admission + "', N'" + categ + "', N'" + contact + "', N'" + website + "', N'" + location + "', N'" + latitude + "', N'" + longitude + "', N'" + country + "', N'" + imagesArr + "')";
//command.ExecuteNonQuery();
int result = command.ExecuteNonQuery();
if (result == 1)
{
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert(' New event has been added')", true);
name.Value = "";
TextArea3.InnerText = "";
DropDownList1.Text = "Month";
category.Value = "Day";
DropDownList2.Text = "Year";
DropDownList4.Text = "Month";
days.Value = "Day";
DropDownList5.Text = "Year";
duration.Value= "";
admission.Value = "";
DropDownList3.Text = "Category";
TextArea4.InnerText = "";
website.Value = "";
venue.Value = "";
Session.Remove("ImagesArray");
Session.Remove("Latitude");
Session.Remove("Longitude");
}
con.Close();
}
}
As seen in the codes above, I've used two different ways to get the value of an html text box value, such as "Request.Form["name"].ToString();" and "name.Value;" and none of them worked, except that the second way has worked for "Venue" field only.
Do you have any idea to solve this???
Well, I've figured out my issue .. in this code
command.CommandText =
"INSERT INTO EventsEnglish( " +
"EventName, EventDescription, EventStartDate, EventEndDate, " +
"EventDuration, EventAdmission, EventCategory, EventContact, " +
"EventWebsite, EventVenue, EventMapLatitude, EventMapLongitude, " +
"CountryName, EventImages) " +
"VALUES (" +
"N'" + name + "', N'" + disc + "', N'" + startDate + "', " +
"N'" + endDate + "',N'" + duration + "',N'" + admission + "', " +
"N'" + categ + "', N'" + contact + "', N'" + website + "', " +
"N'" + location + "', N'" + latitude + "', N'" + longitude + "', " +
"N'" + country + "', N'" + imagesArr + "')";
I just had to add the string local variables instead of the html text boxes names .. I don't know how i didn't notice this!!
I have grid view in which all question has been display from access database . now I want to perform the search operation in given text boxes ,user may enter the data in 1 text box or else in all text boxes ,depends upon user needs .My question is how many times condition has been give so that whatever user give information in any text box ,filtration is performed accordingly.
for eg : user gave only standard and marks than filtration must be perform where standard = "given value" and marks = "given value" only
I have given various condition on each control but its become too huge coding. now wants to minimize this so any suggestion must recommended.
My Code:
private void txt_marks_TextChanged(object sender, EventArgs e)
{
string marks = Convert.ToString(txt_marks.Text);
string q_type = Convert.ToString(cmbQType.SelectedValue);
if (q_type.Contains("[") || q_type.Contains("]") || q_type.Contains("*") || q_type.Contains("%"))
{
q_type = replacestring(q_type);
}
if (btnlanguage.Text != "" && txt_sub.Text != "" && txt_std.Text != "" && cmbQType.SelectedIndex != -1 && txt_marks.Text != "")
{
DataTable dt = main_ds.Tables[0];
dt.DefaultView.RowFilter = String.Format("Subject Like '" + txt_sub.Text.ToString() + "%' and Standard Like '" + txt_std.Text.ToString() + "'and Chapter Like '" + btnlanguage.Text.ToString() + "%' and QuestionType Like '" + q_type + "' and Marks = '" + marks + "'");
DGV_View.DataSource = main_ds.Tables[0].DefaultView;
}
else if (txt_marks.Text != "" && cmbQType.SelectedIndex != -1 && txt_sub.Text != "" && txt_std.Text != "")
{
DataTable dt = main_ds.Tables[0];
dt.DefaultView.RowFilter = String.Format("QuestionType Like '" + q_type + "' and Marks = '" + marks + "' and Subject Like '" + txt_sub.Text.ToString() + "%' and Standard Like '"+ txt_std.Text.ToString()+ "'");
DGV_View.DataSource = main_ds.Tables[0].DefaultView;
}
else if (txt_marks.Text != "" && cmbQType.SelectedIndex != -1 && txt_sub.Text != "")
{
DataTable dt = main_ds.Tables[0];
dt.DefaultView.RowFilter = String.Format("QuestionType Like '" + q_type + "' and Marks = '" + marks + "' and Subject Like '" + txt_sub.Text.ToString() + "%'");
DGV_View.DataSource = main_ds.Tables[0].DefaultView;
}
else if (txt_marks.Text != "" && cmbQType.SelectedIndex != -1)
{
DataTable dt = main_ds.Tables[0];
dt.DefaultView.RowFilter = String.Format(" QuestionType Like '" + q_type + "' and Marks = '" + marks + "'");
DGV_View.DataSource = main_ds.Tables[0].DefaultView;
}
else if (txt_marks.Text != "")
{
DataTable dt = main_ds.Tables[0];
dt.DefaultView.RowFilter = String.Format("Marks = '"+ marks +"'");
DGV_View.DataSource = main_ds.Tables[0].DefaultView;
}
else
{
load_grid_view();
}
Similarly above coding has been done to every given control.
Thank you .
What about using some Function that take n arguments to do some checks?
private void txt_marks_TextChanged(object sender, EventArgs e)
{
string marks = Convert.ToString(txt_marks.Text);
string q_type = Convert.ToString(cmbQType.SelectedValue);
char[] q_types = { '[', ']', '%'};
if (ContainsChars(q_types, q_type))
{
q_type = replacestring(q_type);
}
if (NoEmpty(btnlanguage.Text, txt_sub.Text, txt_std.Text, txt_marks.Text) && cmbQType.SelectedIndex != -1)
{
DataTable dt = main_ds.Tables[0];
dt.DefaultView.RowFilter = String.Format("Subject Like '" + txt_sub.Text.ToString() + "%' and Standard Like '" + txt_std.Text.ToString() + "'and Chapter Like '" + btnlanguage.Text.ToString() + "%' and QuestionType Like '" + q_type + "' and Marks = '" + marks + "'");
DGV_View.DataSource = main_ds.Tables[0].DefaultView;
}
else if (NoEmpty(txt_marks.Text, txt_sub.Text, txt_std.Text) && cmbQType.SelectedIndex != -1)
{
DataTable dt = main_ds.Tables[0];
dt.DefaultView.RowFilter = String.Format("QuestionType Like '" + q_type + "' and Marks = '" + marks + "' and Subject Like '" + txt_sub.Text.ToString() + "%' and Standard Like '"+ txt_std.Text.ToString()+ "'");
DGV_View.DataSource = main_ds.Tables[0].DefaultView;
}
else if (NoEmpty(txt_marks.Text, txt_sub.Text) && cmbQType.SelectedIndex != -1)
{
DataTable dt = main_ds.Tables[0];
dt.DefaultView.RowFilter = String.Format("QuestionType Like '" + q_type + "' and Marks = '" + marks + "' and Subject Like '" + txt_sub.Text.ToString() + "%'");
DGV_View.DataSource = main_ds.Tables[0].DefaultView;
}
else if (txt_marks.Text != "" && cmbQType.SelectedIndex != -1)
{
DataTable dt = main_ds.Tables[0];
dt.DefaultView.RowFilter = String.Format(" QuestionType Like '" + q_type + "' and Marks = '" + marks + "'");
DGV_View.DataSource = main_ds.Tables[0].DefaultView;
}
else if (txt_marks.Text != "")
{
DataTable dt = main_ds.Tables[0];
dt.DefaultView.RowFilter = String.Format("Marks = '"+ marks +"'");
DGV_View.DataSource = main_ds.Tables[0].DefaultView;
}
else
{
load_grid_view();
}
}
public static bool NoEmpty(params string[] strings)
{
return strings.All( x => x != string.Empty );
}
public static bool ContainsChars(IEnumerable<char> chars, string toTest)
{
return chars.Any(x => toTest.Contains(x));
}
Please note that I've written it with notepad++ so I don't have typo checks, so excuse me if there's any typo
Perhaps you can store the field query in the Tag property of each control (e.g. txt_marks.Tag would be set to "Marks ='{0}'") then you can define an extensiom method to get the query from a TextBox and another for the drop down, something like:
internal static string GetQuery(this TextBox textBox)
{
if(string.IsNullOrEmpty(textBox.Text)) return string.Empty;
return string.Format(textBox.Tag.ToString(), textBox.Text)
}
internal static string GetQuery(this ComboBox cmbBox)
{
if(cmbBox.SelectedIndex == -1) return string.Empty;
return string.Format(cmbBox.Tag.ToString(), cmbBox.SelectedValue)
}
Then you can just loop through the controls, call GetQuery and do a string.Join("and ", controlQueries.Where(q => !string.IsNullOrEmpty(q))
Thank you #KMoussa and #Sid .
With your Combine Both suggestion I made a Dynamic query in function and call this function on every control and also like to share with this site .
My function :
public void searching_query()
{
string grid_query = "";
int cnt_coma = 0;
string q_type = "";
if (txt_marks.Text != "")
{
string marks = Convert.ToString(txt_marks.Text);
}
if (cmbQType.SelectedIndex != -1)
{
q_type = Convert.ToString(cmbQType.SelectedValue);
// Removing the wild character in question type .
if (q_type.Contains("[") || q_type.Contains("]") || q_type.Contains("*") || q_type.Contains("%"))
{
q_type = replacestring(q_type);
}
}
// counting the number of fields has been enter ->(for entering "and" in between in query)
{
if (txt_std.Text != "")
cnt_coma = 1;
if (txt_sub.Text != "")
cnt_coma = 2;
if (Txt_chp.Text != "")
cnt_coma = 3;
if (cmbQType.SelectedIndex != -1)
cnt_coma = 4;
if (txt_marks.Text != "")
cnt_coma = 5;
}
// making query for searching .
if (txt_std.Text != "")
{
if (cnt_coma > 1)
grid_query = grid_query + "Standard Like '" + txt_std.Text.ToString() + "' and ";
else if (cnt_coma <= 1)
grid_query = grid_query + "Standard Like '" + txt_std.Text.ToString() + "'";
}
if (txt_sub.Text != "")
{
if (cnt_coma > 2)
grid_query = grid_query + "Subject Like '" + txt_sub.Text.ToString() + "%' and ";
else if (cnt_coma <= 2 )
grid_query = grid_query + "Subject Like '" + txt_sub.Text.ToString() + "%' ";
}
if (Txt_chp.Text != "")
{
if (cnt_coma > 3)
grid_query = grid_query + "Chapter Like '" + Txt_chp.Text.ToString() + "%' and ";
else if (cnt_coma <= 3 )
grid_query = grid_query + "Chapter Like '" + Txt_chp.Text.ToString() + "%'";
}
if (cmbQType.SelectedIndex != -1)
{
if (cnt_coma > 4)
grid_query = grid_query + "QuestionType Like '" + q_type + "' and ";
else if (cnt_coma <= 4 )
grid_query = grid_query + "QuestionType Like '" + q_type + "'";
}
if (txt_marks.Text != "")
{
grid_query = grid_query + "Marks = '" + Convert.ToString(txt_marks.Text) + "'";
}
//---------- Grid view Filteration
if (cnt_coma > 0)
{
DataTable dt = main_ds.Tables[0];
dt.DefaultView.RowFilter = String.Format(grid_query);
DGV_View.DataSource = main_ds.Tables[0].DefaultView;
}
else
{
load_grid_view();
}
}
I'm really having trouble adding a condition that show message when user left the text box blank.I've tried every way that i know of to change it but it's not working at all.I have "5" textbox and hiding and showing them based on selected combobox item value for example if i selected firearm it should all five textbox and if i selected ammo then it should only show three textbox(1,2 and 3).And it should show message box warning me if i left a single textbox blank.
But the problem is during the ammo setting the message box kept showing up even though i have filled all of the textfield.Is there something wrong with my if else statement?
private void insertbtn_Click(object sender, EventArgs e)
{
string mysql = "";
if (comboBox1.SelectedItem.ToString() == "Firearm")
{
mysql = "insert into Firearm(Fid,Fname,Ftype,Manufacturer,Price) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "')";
}
if (comboBox1.SelectedItem.ToString() == "Ammo")
{
mysql = "insert into Ammo(Aid,Atype,Coating,Metal) values('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";
}
if (comboBox1.SelectedItem.ToString() == "Ammo" && textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" )
{
MessageBox.Show("Please Fill all of the text fields");
}
else if (comboBox1.SelectedItem.ToString()=="Firearm" && textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "" || textBox5.Text=="" )
{
MessageBox.Show("Please Fill all of the text fields");
}
else
{
try
{
SqlConnection conn = new SqlConnection(dbsource);
conn.Open();
SqlCommand cmd = new SqlCommand(mysql, conn);
cmd.ExecuteNonQuery();
MessageBox.Show("New Data Inserted!");
conn.Close();
}
catch (SqlException)
{
MessageBox.Show("Error!!!");
}
}
}
Your problem is probably at this line:
if(comboBox1.SelectedItem.ToString() == "Ammo" &&
textBox1.Text == "" ||
textBox2.Text == "" ||
textBox3.Text == "")
I assume you want to say that is the value is "Ammo" and one of the text boxes are empty: (add another set of ()
if(comboBox1.SelectedItem.ToString() == "Ammo" &&
(textBox1.Text == "" ||
textBox2.Text == "" ||
textBox3.Text == ""))
And same for else if of "Firearm"
I have the following IF condition in one of my programs, I set the condition to validate whether the mandatory text fields are empty, if so, to display an Error message, But even when the mandatory fields are empty still the records being saved regardless of mandatory fields.
if (!txt_teacherid.Equals(null) && !txt_teacherid.Equals("") && !txt_teacherfname.Equals(null) && !txt_teacherfname.Equals("") && !txt_teacherlname.Equals(null) && !txt_teacherlname.Equals("") && !txt_teacherdob.Equals(null) && !txt_teacherdob.Equals("") && !txt_teachernationality.Equals(null) && !txt_teachernationality.Equals("") && !txt_teacheraddress.Equals(null) && !txt_teacheraddress.Equals(""))
{
String teacherid = txt_teacherid.Text.Trim();
String teacherfname = txt_teacherfname.Text.Trim();
String teacherlname = txt_teacherlname.Text.Trim();
String teachergender = opt_gender.SelectedItem.Value.ToString();
String teachercivilstatus = opt_civilstatus.SelectedItem.Value.ToString();
String teacherdob = txt_teacherdob.Text.Trim();
String teachernationality = txt_teachernationality.Text.Trim();
String teacheraddress = txt_teacheraddress.Text.Trim();
String teachercontactno = txt_teachercontactno.Text.Trim();
String teacherqualification = txt_teacherqualification.Text.Trim();
String teacherexperience = txt_teacherexperience.Text.Trim();
String teacherjobtitle = txt_teacherjobtitle.Text.Trim();
String teacherjoindate = txt_teacherjoindate.Text.Trim();
String imgpath = (String)Session["imagepath"];
DBConnection db = new DBConnection();
db.getConnection();
db.executeUpdateQuery("INSERT INTO Teacher (TeacherID,TeacherFirstName,TeacherLastName,TeacherGender,TeacherDOB,TeacherCivilStatus,TeacherNationality,TeacherQualification,TeacherExperience,TeacherJobTitle,TeacherAddress,TeacherContactNo,TeacherJoinDate,ImagePath) VALUES ('" + teacherid + "','" + teacherfname + "','" + teacherlname + "','" + teachergender + "','" + teacherdob + "','" + teachercivilstatus + "','" + teachernationality + "','" + teacherqualification + "','" + teacherexperience + "','" + teacherjobtitle + "','" + teacheraddress + "','" + teachercontactno + "','" + teacherjoindate + "','" + imgpath + "')");
Session["imagepath"] = null;
Page.ClientScript.RegisterStartupScript(this.GetType(), "Call my function", "recordInserted();window.location.href='AdminRegisterTeacher.aspx'", true);
//Response.Redirect("AdminRegisterTeacher.aspx");
}
else
{
InnerError ie = new InnerError();
ie.throwError("Oops! There was an error, Make sure you have filled all mandatory data");
}
if (!txt_teacherid.Equals(null) && !txt_teacherid.Equals("")... is wrong as your are checking against the control txt_teacherid and not the text.
it should simply be
if (!String.IsNullOrEmpty(txt_teacherid.Text.Trim())... )
or use String.IsNullOrWhiteSpace (.Net 4 and up):
if (!String.IsNullOrWhiteSpace(txt_teacherid.Text) && ... )
And also note you should use parameterized queries to protect against SQL injection.
You should use one of the following:
string.IsNullOrEmpty()
string.IsNullOrWhiteSpace()
String has method which is .IsNullOrEmpty() which will return a boolean. Have you tried using that instead?
So would be:
if (!txt_teacherid.IsNullOrEmpty() && !txt_teacherfname.IsNullOrEmpty()&& !txt_teacherlname..IsNullOrEmpty() && !txt_teacherdob.IsNullOrEmpty() && !txt_teachernationality.IsNullOrEmpty() && !txt_teacheraddress.IsNullOrEmpty())
{
//do database stuff here
}
Use following code:
if (!String.IsNullOrEmpty(txt_teacherid) && !String.IsNullOrEmpty(txt_teacherfname) && !String.IsNullOrEmpty(txt_teacherlname) && !String.IsNullOrEmpty(txt_teacherdob) && !String.IsNullOrEmpty(txt_teachernationality) && !String.IsNullOrEmpty(txt_teacheraddress))
{
\\Save Data
}
else
{
\\show error
}
Use below code
if (!txt_teacherid.Text.Equals(null) && !txt_teacherid.Text.Equals("") && !txt_teacherfname.Text.Equals(null) && !txt_teacherfname.Text.Equals("") && !txt_teacherlname.Text.Equals(null) && !txt_teacherlname.Text.Equals("") && !txt_teacherdob.Text.Equals(null) && !txt_teacherdob.Text.Equals("") && !txt_teachernationality.Text.Equals(null) && !txt_teachernationality.Text.Equals("") && !txt_teacheraddress.Text.Equals(null) && !txt_teacheraddress.Text.Equals(""))
In place of your existing condition