How can i put validation for txtPName and txtAddress if they are empty i cannot proceed to submit and a messagebox will pop up.
private void btnSubmit_Click(object sender, EventArgs e)
{
string insertQuery = "INSERT INTO patientdb.addpatient(PatientName,MobileNumber,Occupation,Gender,Address,Age,PhoneNumber,MedicalHistory,ChiefComplaint) VALUES ('" + txtPName.Text + "','" + txtMNum.Text + "','" + txtOccup.Text + "','" + comboBox1.Text + "','" + txtAddress.Text + "','" + txtAge.Text + "','" + txtPNum.Text + "','" + rtbMHistory.Text + "','" + rtbCC.Text + "')";
con.Open();
MySqlCommand command = new MySqlCommand(insertQuery, con);
try
{
if (command.ExecuteNonQuery() == 1)
{
MessageBox.Show("Data Inserted");
txtPName.Text = "";
txtMNum.Text = "";
txtPNum.Text = "";
txtAddress.Text = "";
txtAge.Text = "";
txtOccup.Text = "";
rtbMHistory.Text = "";
rtbCC.Text = "";
comboBox1.Text = " ";
}
else
{
MessageBox.Show("Data Not Inserted");
}
}
You can add a validation check before executing the rest of the code. Calling return will immediately leave the method after validation fails.
private void btnSubmit_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtPName.Text) || string.IsNullOrEmpty(txtAddress.Text))
{
MessageBox.Show("Missing Data");
return;
}
// Your code here...
Related
I am Using MS Access DataBase.
I am trying to add Data in the table, But After adding a column id AutoNumber in the table. it gives an error. Please Guide me How I can solve this.
private void button1_Click_1(object sender, EventArgs e)
{
OleDbConnection sc = new OleDbConnection(connectionString);
OleDbCommand sm = new OleDbCommand("insert into prod values('" + textBox13.Text + "','" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + textBox6.Text + "','" + textBox7.Text + "','" + textBox8.Text + "','" + textBox9.Text + "','" + textBox10.Text + "','" + textBox11.Text + "','" + textBox12.Text + "')", sc);
//SqlCommand sm = new SqlCommand("insert into prod values(N'" + textBox1.Text + "',N'" + textBox2.Text + "',N'" + textBox3.Text + "',N'" + textBox4.Text + "',N'" + textBox5.Text + "',N'" + textBox6.Text + "',N'" + textBox7.Text + "',N'" + textBox8.Text + "',N'" + textBox9.Text + "',N'" + textBox10.Text + "',N'" + textBox11.Text + "',N'" + textBox12.Text + "',N'" + textBox13.Text + "')", sc);
sc.Open();
sm.ExecuteNonQuery();
//sm.ExecuteNonQuery();
sc.Close();
}
Error:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
Additional information: Data type mismatch in criteria expression.
Always uses parameters to properly type data for inserts, updates, deletes and select/where.
Example
using System;
using System.Data.OleDb;
using System.Windows.Forms;
namespace AccessSamples
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void AddButton_Click(object sender, EventArgs e)
{
var (exception, identifier) = DataOperations.Add(
"New company",
"Some contact",
DateTime.Now);
if (exception is null)
{
MessageBox.Show($"New id {identifier}");
}
}
}
public class DataOperations
{
private static string _connectionString =>
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=NorthWind.accdb";
public static (Exception exception, int identifier) Add(string companyName, string contactName, DateTime modified)
{
try
{
using (var cn = new OleDbConnection { ConnectionString = _connectionString })
{
using (var cmd = new OleDbCommand { Connection = cn })
{
cmd.CommandText = "INSERT INTO Customers (CompanyName,ContactName,Modified) " +
"VALUES (#CompanyName,#ContactName,#Modified)";
cmd.Parameters.Add(new OleDbParameter("#CompanyName", OleDbType.LongVarChar));
cmd.Parameters.Add(new OleDbParameter("#ContactName", OleDbType.LongVarChar));
cmd.Parameters.Add(new OleDbParameter("#Modified", OleDbType.Date));
cmd.Parameters["#CompanyName"].Value = companyName;
cmd.Parameters["#ContactName"].Value = contactName;
cmd.Parameters["#Modified"].Value = modified;
cn.Open();
cmd.ExecuteNonQuery();
cmd.CommandText = "SELECT ##Identity";
return (null, Convert.ToInt32(cmd.ExecuteScalar()));
}
}
}
catch (Exception ex)
{
return (ex, -1);
}
}
}
}
I'm a beginner in C# and I have a problem with image uploading.
Everything in my code inserting in my database except for the files that I uploaded, I didn't know why it doesn't save it in the database, it only saved when I remove the Response.Redirect("Personalinformation.aspx") but I can't remove this response redirect because I need it.
protected void Button8_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
if (con.State == System.Data.ConnectionState.Open)
{
if (TextBox11.Text != "" && TextBox8.Text != "" && TextBox9.Text != "" )
{
if (FileUpload1.PostedFile != null)
{
if (FileUpload2.PostedFile != null)
{
string FileName = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
string FileName1 = System.IO.Path.GetFileName(FileUpload1.PostedFile.FileName);
//Save files to disk
FileUpload1.SaveAs(Server.MapPath("/upload/" + FileName));
FileUpload2.SaveAs(Server.MapPath("/identification/" + FileName1));
String q = "Insert into dbo.requests(request_type,visit_date,reason,request_date,status_id,user_id,user_name,FileName,FilePath,End_vdate,FileName1,FilePath1,RequestNotes,VisitorType)values(N'" + DropDownList1.SelectedValue + "',N'" + TextBox8.Text + "',N'" + TextBox9.Text + "','" + DateTime.Now + "','4','" + Session["empNo"] + "',N'" + Session["ArbnName"] + "' , #FileName , #FilePath ,N'" + TextBox10.Text + "',#FileName1 , #FilePath1)";
SqlCommand cmd = new SqlCommand(q, con);
cmd.Parameters.AddWithValue("#FileName", FileName);
cmd.Parameters.AddWithValue("#FilePath", "/upload/" + FileName);
cmd.Parameters.AddWithValue("#FileName1", FileName1);
cmd.Parameters.AddWithValue("#FilePath1", "/identification/" + FileName1);
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
}
}
else
{
String q = "Insert into dbo.requests(request_type,visit_date,reason,request_date,status_id,user_id,user_name,End_vdate,phone_ext)values(N'" + DropDownList1.SelectedValue + "',N'" + TextBox8.Text + "',N'" + TextBox9.Text + "','" + DateTime.Now + "','4','" + Session["empNo"] + "' ,N'" + Session["ArbnName"] + "',N'" + TextBox10.Text + "','" + TextBox11.Text.ToString() + "')";
SqlCommand cmd = new SqlCommand(q, con);
cmd.ExecuteNonQuery();
}
response.redirect("Personalinformation.aspx");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Scripts", "<script>alert(' هناك حقول مطلوبة فارغة ');</script>");
}
String c = "Insert into dbo.logFile(user_id,transaction_date,action_type) values ('" + Session["empNo"] + "', '" + DateTime.Now + "' ,N' طلب قبول زائر') ";
SqlCommand cmdc = new SqlCommand(c, con);
cmdc.ExecuteNonQuery();
con.Close();
}
}
protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("Default.aspx");
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex == 0) //index of long visit
{
FileUpload1.Visible = false;
FileUpload2.Visible = false;
Button6.Visible = false;
TextBox10.Visible = false;
Label2.Visible = false;
Label3.Visible = false;
}
else
{
FileUpload1.Visible = true;
FileUpload2.Visible = true;
Button6.Visible = true;
TextBox10.Visible = true;
Label2.Visible = true;
Label3.Visible = true;
}
}
Instead of Response.Redirect, you can try using Server.Transfer if you intend to transfer the user to other page.
See more details at difference between Server.Transfer and Response.Redirect?
You have used FileUpload1.SaveAs:
FileUpload1.SaveAs(Server.MapPath("/upload/" + FileName));
FileUpload2.SaveAs(Server.MapPath("/identification/" + FileName1));
Instead of that use this:
FileUpload1.PostedFile.SaveAs(Server.MapPath("/upload/" + FileName));
FileUpload2.PostedFile.SaveAs(Server.MapPath("/identification/" + FileName1));
You are missing PostedFile keyword in that.
This is my first project, so be gentle
I know how to get the current row Index value and its [ID] value using the following code:
public void Sql_Address_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
DataGrid gd = (DataGrid)sender;
if (gd.SelectedItem is DataRowView row_selected)
{
Public_Strings.selectedID = Int32.Parse(row_selected["ID"].ToString());
Public_Strings.currentIndex = Int32.Parse(sql_address.SelectedIndex.ToString());
}
}
I am displaying synchronized SQL table values in two different places - a DataGrid in TabItem 1 and a couple of editable TextBoxes in TabItem 2. I also have Next/Previous buttons in TabItem 2 to move up and down the DataGrid Index that also refresh the content of the TextBoxes. Everything works fine, but when I add or modify an entry in the SQL table, the Index shifts, because of the grouping and the Next/Previous buttons reset to the default Index 0.
I know how to bypass this when Deleting an entry by using this method:
public void Delete(object sender, RoutedEventArgs e)
{
MessageBoxResult messageBoxResault = System.Windows.MessageBox.Show("Ali se prepričani?", "Potrditev izbrisa", System.Windows.MessageBoxButton.YesNo);
if (messageBoxResault == MessageBoxResult.Yes)
{
Public_Strings.currentIndex= sql_address.SelectedIndex-1;
SqlCommand cmd = new SqlCommand
{
CommandText = "DELETE FROM cbu_naslovi WHERE [ID]='" + Public_Strings.selectedID + "'",
Connection = con
};
cmd.ExecuteNonQuery();
Datagrid();
sql_address.SelectedIndex = Public_Strings.currentIndex;
}
}
My Add method:
public void Add(object sender, RoutedEventArgs e)
{
MessageBoxResult messageBoxResault = System.Windows.MessageBox.Show("Ali se prepričani?", "Potrditev vnosa", System.Windows.MessageBoxButton.YesNo);
if (messageBoxResault == MessageBoxResult.Yes)
{
SqlCommand cmd = new SqlCommand
{
CommandText = "INSERT INTO cbu_naslovi VALUES ('" + ulica.Text + "','" + hisna_st.Text + "','" + id_hise.Text + "','" + postna_st.Text + "','" + obmocje.Text + "','" + katastrska_obcina.Text + "','" + st_objekta.Text + "','" + st_delov.Text + "','" + st_parcele_1.Text + "','" + st_parcele_2.Text + "','" + st_parcele_3.Text + "','" + st_parcele_4.Text + "','" + st_parcele_5.Text + "','" + st_parcele_6.Text + "','" + st_parcele_7.Text + "')",
Connection = con
};
cmd.ExecuteNonQuery();
Datagrid();
address.Content = ulica.Text.ToString() + " " + hisna_st.Text.ToString() + id_hise.Text.ToString();
}
}
I need a solution that allows me to select the index based on the ID value of row, so that when I add or modify and entry in the SQL table the Next/Previous buttons continue from the newly added/modified index. Basically something in the lines of:
sql_address.SelectedIndex = "sql_address.SelectedIndex where sql_address[ID] = Public_Strings.currentIndex" - Paraphrasing
Visual refference:
https://image.ibb.co/k2XDAz/1.png
https://image.ibb.co/gJ00qz/2.png
I solved this issue using the following combination of code:
public void Add(object sender, RoutedEventArgs e)
{
MessageBoxResult messageBoxResault = System.Windows.MessageBox.Show("Ali se prepričani?", "Potrditev vnosa", System.Windows.MessageBoxButton.YesNo);
if (messageBoxResault == MessageBoxResult.Yes)
{
SqlCommand cmd = new SqlCommand
{
CommandText = "INSERT INTO cbu_naslovi VALUES ('" + ulica.Text + "','" + hisna_st.Text + "','" + id_hise.Text + "','" + postna_st.Text + "','" + obmocje.Text + "','" + katastrska_obcina.Text + "','" + st_objekta.Text + "','" + st_delov.Text + "','" + st_parcele_1.Text + "','" + st_parcele_2.Text + "','" + st_parcele_3.Text + "','" + st_parcele_4.Text + "','" + st_parcele_5.Text + "','" + st_parcele_6.Text + "','" + st_parcele_7.Text + "')",
Connection = con
};
cmd.ExecuteNonQuery();
SaveID();
sql_address.SelectedIndex = 0;
SearchIndex();
address.Content = ulica.Text.ToString() + " " + hisna_st.Text.ToString() + id_hise.Text.ToString();
search.Text = string.Empty;
}
}
public void SaveID()
{
DatagridIndex();
sql_address.SelectedIndex = sql_address.Items.Count - 1;
Public_Strings.saveID3 = Public_Strings.saveID1;
Datagrid();
}
public void SearchIndex()
{
if (Public_Strings.saveID3 == Public_Strings.saveID1) { }
else
{
sql_address.SelectedIndex++;
SearchIndex();
}
}
public void DatagridIndex()
{
SqlCommand cmd = new SqlCommand
{
CommandText = "SELECT * FROM [cbu_naslovi] ORDER BY [ID] ASC",
Connection = con
};
SqlDataAdapter da = new SqlDataAdapter(cmd);
dataGrid1 = new DataTable("cbu_naslovi");
da.Fill(dataGrid1);
sql_address.ItemsSource = dataGrid1.DefaultView;
}
public void Datagrid()
{
SqlCommand cmd = new SqlCommand
{
CommandText = "SELECT * FROM [cbu_naslovi] ORDER BY [ULICA] ASC, LEN ([HS]) ASC, [HS] ASC, [HID] ASC",
Connection = con
};
SqlDataAdapter da = new SqlDataAdapter(cmd);
dataGrid1 = new DataTable("cbu_naslovi");
da.Fill(dataGrid1);
sql_address.ItemsSource = dataGrid1.DefaultView;
}
TLDR version, add an entry and create a "new" Datagrid ordered by ID ASC, the last ID on the list is always going to be the newly created one as long as you are using auto-increment. Save that ID in a NEW string. Now call for the "correct" Datagrid, order it the way you want and compare the IDs starting from Index 0 with the saved one until you find the right one, then stop the code. Your add button should now redirect you to the correct index and your next/previous buttons should work fine.
Edit_v1:
There might be an easier solution, but I'm too stupid to find it (could theoretically solve it with a method that adds +1 to a counter every time you press the Add button, but be careful that you start with the correct number of IDs when importing CVS file).
Edit_v2: Or just SQL to find the last ID:
Safest way to get last record ID from a table
Then use the following method to convert it to string:
How can I get SQL result into a STRING variable?
Edit_v3: Another method:
public void Add(object sender, RoutedEventArgs e)
{
if (ulica.Text != "" && hisna_st.Text != "" && postna_st.Text != "" && obmocje.Text != "")
{
MessageBoxResult messageBoxResault = MessageBoxEx.Show(this, "Ali se prepričani?", "Potrditev vnosa", MessageBoxButton.YesNo);
if (messageBoxResault == MessageBoxResult.Yes)
{
SqlCommand cmd = new SqlCommand
{
CommandText = "INSERT INTO cbu_naslovi VALUES ('" + ulica.Text + " " + hisna_st.Text + id_hise.Text + "','" + ulica.Text + "','" + hisna_st.Text + "','" + id_hise.Text + "','" + postna_st.Text + "','" + obmocje.Text + "','" + katastrska_obcina.Text + "','" + st_objekta.Text + "','" + st_delov.Text + "','" + st_parcele_1.Text + "','" + st_parcele_2.Text + "','" + st_parcele_3.Text + "','" + st_parcele_4.Text + "','" + st_parcele_5.Text + "','" + st_parcele_6.Text + "','" + st_parcele_7.Text + "','" + st_parcele_8.Text + "','" + st_parcele_9.Text + "','" + st_parcele_10.Text + "','" + st_parcele_11.Text + "','" + st_parcele_12.Text + "','" + st_parcele_13.Text + "','" + st_parcele_14.Text + "','" + st_parcele_15.Text + "','" + st_parcele_16.Text + "','" + st_parcele_17.Text + "'); SELECT SCOPE_IDENTITY();",
Connection = con
};
int lastId = Convert.ToInt32(cmd.ExecuteScalar());
InvokeDataGridAddress();
SetToRow(lastId);
address.Content = ulica.Text.ToString() + " " + hisna_st.Text.ToString() + id_hise.Text.ToString();
}
}
else
{
MessageBoxEx.Show(this, "Vpisati je potrebno podatke!");
}
}
public int CurrentID
{
get
{
int tmp = 0;
if (dg_address.SelectedIndex >= 0)
{
int.TryParse(dtAddress.Rows[dg_address.SelectedIndex].ItemArray[0].ToString(), out tmp);
}
return tmp;
}
}
public void SetToRow(int Id)
{
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
dg_address.SelectionChanged -= DG_Address_SelectionChanged;
while (CurrentID != Id && dg_address.SelectedIndex < dtAddress.Rows.Count - 1)
{
dg_address.SelectedIndex++;
}
dg_address.SelectionChanged += DG_Address_SelectionChanged;
Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;
}
I'm getting this error code: "unclosed quotation mark after the character string" on the line: cmd.ExecuteNonQuery();
I've looked, but I don't know what's wrong. I also tried just putting two of the textboxe, but I can't seem to debug it. Please advise. Thanks!
Here's the code:
namespace Inventory
{
public partial class NewData : System.Web.UI.Page
{
SqlConnection cn = new SqlConnection("Data Source=10.10.101.188;Initial Catalog=ActioNetITInventory;User ID=rails.sa;Password=ActioNet1234");
protected void Page_Load(object sender, EventArgs e)
{
}//end page load
protected void addButton_Click(object sender, EventArgs e)
{
cn.Open();
SqlCommand cmd = cn.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "INSERT INTO Inventory values('" + Typetb.Text + " ',' " + Maketb.Text + "','" + Modeltb.Text + "','" + Serialtb.Text + "','" + Assignedtb.Text + "','" + Locationtb.Text + "','" + Notestb.Text + "')'";
cmd.ExecuteNonQuery();
cn.Close();
status.Visible = true;
status.Text = "Added succesffully!";
Typetb.Text = "";
Maketb.Text = "";
Modeltb.Text = "";
Serialtb.Text = "";
Assignedtb.Text = "";
Locationtb.Text = "";
Notestb.Text = "";
}//end add button
protected void clearButton_Click1(object sender, EventArgs e)
{
Typetb.Text = "";
Maketb.Text = "";
Modeltb.Text = "";
Serialtb.Text = "";
Assignedtb.Text = "";
Locationtb.Text = "";
Notestb.Text = "";
}//clear button
}//end
}//end
As far as I can see, you have unnecessary single quote at the end of your query.
Notestb.Text + "')'
^^ here
But more important
You should always use parameterized queries. This kind of string concatenations are open for SQL Injection attacks.
Also use using statement to dispose your connections and commands automatically instead of calling Close or Dispose methods manually.
using(var cn = new SqlConnection(conString))
using(var cmd = cn.CreateCommand())
{
// Set your CommandText property with your parameter definitions
// Add your parameters and their values with Add method
// Open your connection
// Execute your query.
}
Your command ends with an extra single quote. It should be:
cmd.CommandText = "INSERT INTO Inventory values('" +
Typetb.Text + " ',' " + Maketb.Text + "','" + Modeltb.Text +
"','" + Serialtb.Text + "','" + Assignedtb.Text + "','" +
Locationtb.Text + "','" + Notestb.Text + "')";
I think the problem is
cmd.CommandText = "INSERT INTO Inventory values('" + Typetb.Text + " ',' "
+ Maketb.Text + "','" + Modeltb.Text + "','" + Serialtb.Text + "','" +
Assignedtb.Text + "','" + Locationtb.Text + "','" + Notestb.Text + "')'";
there you single comma ' after the right bracket ).
Should have been:
cmd.CommandText = "INSERT INTO Inventory values('" + Typetb.Text + " ',' "
+ Maketb.Text + "','" + Modeltb.Text + "','" + Serialtb.Text + "','"
+ Assignedtb.Text + "','" + Locationtb.Text + "','" + Notestb.Text
+ "')";
I have a textbox with autopostback property true and a button for saving.
On text changed, I get data from a database, and display in other textboxes. When I edit the textboxes and then save, the textchanged event fires, and the data does not update. Instead it saves the previous data only. I want to save the edited data.
Can anyone help me do this?
Here is the button click event:
protected void btnSave_Click(object sender, EventArgs e)
{
//TextBox1.Text = exists;
if(exists=="yes")
{
OdbcConnection DbConnection2 = new OdbcConnection(con1);
OdbcCommand DbCommand2 = DbConnection2.CreateCommand();
try
{
DbConnection2.Open();
DbCommand2.CommandText = "update tbl_trip_login set username='" + txtUser.Text.ToUpper() + "',password='" + txtPwd.Text + "',name='" + txtname.Text + "',department='" + txtDept.Text + "',designation='" + txtDesg.Text + "',DOJ='" + txtDOJ.Text + "',DOB='" + txtDOJ.Text + "',phone='" + txtPh.Text + "',Email='" + txtEmail.Text + "',Gender='" + rdbGender.SelectedItem.Text + "',Active='" + rdbActive.SelectedItem.Text + "' where upper(username)=upper('" + txtUser.Text + "')";
TextBox1.Text = DbCommand2.CommandText.ToString();
int t2 = DbCommand2.ExecuteNonQuery();
if (t2 == 1)
{
lblError.Visible = true;
lblError.Text = "Successfully Saved";
}
else
{
lblError.Text = "Not Saved.. Try again later";
lblError.Visible = true;
}
DbConnection2.Close();
}
catch (Exception e1)
{
lblError.Text = e1.Message;
lblError.Visible = true;
DbConnection2.Close();
}
}
else //if user doesn't exists,create new user
{
DateTime dd = DateTime.Now; //current date and time
string custom = dd.ToString("dd-MMM-yyyy,hh:mm,tt"); // to convert in the form : 14-APR-2013 01:35 PM
string ss = "to_date('" + custom + "','dd-mon-yyyy HH:MI AM')"; // oracle does not take only time by default, so use to_date(), and pass this string variable directly in the query
OdbcConnection DbConnection1 = new OdbcConnection(con1);
OdbcCommand DbCommand1 = DbConnection1.CreateCommand();
try
{
DbConnection1.Open();
DbCommand1.CommandText = "insert into tbl_trip_login(username,password,name,department,designation,DOJ,DOB,phone,Email,Gender,Active,Entered_by,Entered_time)values('" + txtUser.Text + "','" + txtPwd.Text + "','" + txtname.Text + "','" + txtDept.Text + "','" + txtDesg.Text + "','" + txtDOJ.Text + "','" + txtDOB.Text + "','" + txtPh.Text + "','" + txtEmail.Text + "','" + rdbGender.SelectedItem.Text + "','" + rdbActive.SelectedItem.Text + "','" + Session["UserAuthentication"].ToString() + "','" + ss + "')";
TextBox1.Text = DbCommand1.CommandText.ToString();
int t1 = DbCommand1.ExecuteNonQuery();
if (t1 == 1)
{
lblError.Visible = true;
lblError.Text = "Successfully Saved";
}
else
{
lblError.Text = "Not Saved.. Try again later";
lblError.Visible = true;
}
DbConnection1.Close();
}
catch (Exception e1)
{
lblError.Text = e1.Message;
lblError.Visible = true;
DbConnection1.Close();
}
txtUser.Focus();
txtUser.Text = "";
txtPwd.Text = "green";
}
}
And the Text Changed event:
protected void txtUser_TextChanged(object sender, EventArgs e)
{
var targetID = Request.Form["__EVENTTARGET"];
if (targetID != null && targetID != string.Empty)
{
btnSave.Enabled = true;
exists = "no";
try
{
OdbcConnection myOdbcConnection = new OdbcConnection(con1);
OdbcCommand myOdbcCommand = myOdbcConnection.CreateCommand();
string sSQL = "select username,password,name,department,designation,doj,dob,phone,email,gender,active from tbl_trip_login where upper(username)=upper('" + txtUser.Text + "')";
myOdbcCommand.CommandText = sSQL;
myOdbcConnection.Open();
OdbcDataReader myOdbcDataReader = myOdbcCommand.ExecuteReader();
if (myOdbcDataReader.HasRows)
{
exists = "yes";
txtPwd.Text = myOdbcDataReader[1].ToString();
txtname.Text = myOdbcDataReader[2].ToString();
txtDept.Text = myOdbcDataReader[3].ToString();
txtDesg.Text = myOdbcDataReader[4].ToString();
txtDOJ.Text = myOdbcDataReader[5].ToString();
txtDOB.Text = myOdbcDataReader[6].ToString();
txtPh.Text = myOdbcDataReader[7].ToString();
txtEmail.Text = myOdbcDataReader[8].ToString();
rdbGender.Text = myOdbcDataReader[9].ToString();
rdbActive.Text = myOdbcDataReader[10].ToString();
}
}
catch (Exception ex)
{
lblError.Text = ex.Message;
lblError.Visible = true;
}
}
}