response redirect conflict with image inserting - c#

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.

Related

how to put validation for certain empty textbox

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...

Local database not refreshing after updating data from C#

I'm working with a local database, and it works well, the whole app. The problem is that I'm facing with some annoying things. If I update, or add new data to my local database, I have to close the whole app and start it again so I can see the new data I have entered. Why is it not refreshing and how can I solve it?
Here is how I add data:
private void button1_Click(object sender, EventArgs e)
{
if (radioButton1.Checked)
{
label5.Text = "1";
}
else
{
label5.Text = "0";
}
if (radioButton2.Checked)
{
label5.Text = "2";
}
if (textBox1.Text.Length == 0)
{
textBox1.Text = "Fara";
}
if (textBox2.Text.Length == 0)
{
textBox2.Text = "0";
}
if (textBox3.Text.Length == 0)
{
textBox3.Text = "0";
}
if (numeTextBox.TextLength != 0 && prenumeTextBox.TextLength != 0)
{
var connString = (#"Data Source=" + Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName + #"\Angajati.sdf");
//var connString = #"Data Source=C:\Users\Andrei\Documents\Visual Studio 2010\Projects\Stellwag\Stellwag\Angajati.sdf";
using (var conn = new SqlCeConnection(connString))
{
try
{
//deschide conectiunea in db
conn.Open();
//creaza comanda in SQL Server CE
SqlCeCommand cmd = new SqlCeCommand();
//conecteaza cmd la conn
cmd.Connection = conn;
//adauga parametru pt campul poza cu value image
SqlCeParameter picture = new SqlCeParameter("#Poza", SqlDbType.Image);
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
byte[] a = ms.GetBuffer();
ms.Close();
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("#Poza", a);
cmd.CommandText = "INSERT INTO info(Nume, Prenume, Data, Proiect, Schimburi, Poza, Acord, Baza) VALUES('" + numeTextBox.Text.Trim() + "', '" + prenumeTextBox.Text.Trim() + "', '" + dateTimePicker1.Value.ToShortDateString() + "', '" + textBox1.Text.Trim() + "', " + label5.Text + " , #Poza, " + textBox2.Text + ", " + textBox3.Text + ");";
cmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Salvat cu succes!");
textBox1.Clear();
textBox2.Clear();
textBox3.Clear();
numeTextBox.Clear();
prenumeTextBox.Clear();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
else
{
MessageBox.Show("Trebuie sa completezi campurile inainte de a salva!");
}
}
Here is how I update it:
private void button1_Click_1(object sender, EventArgs e)
{
//var connString = (#"Data Source= |DataDirectory|\Angajati.sdf");
var connString = (#"Data Source=" + System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) + #"\Angajati.sdf");
using (var conn = new SqlCeConnection(connString))
{
try
{
conn.Open();
SqlCeCommand cmd = new SqlCeCommand();
//conecteaza cmd la conn
cmd.Connection = conn;
//adauga parametru pt campul poza cu value image
SqlCeParameter picture = new SqlCeParameter("#Poza", SqlDbType.Image);
MemoryStream ms = new MemoryStream();
pictureBox1.Image.Save(ms, pictureBox1.Image.RawFormat);
byte[] a = ms.GetBuffer();
ms.Close();
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("#Poza", a);
var query = "UPDATE info SET Nume='" + textBox5.Text + "' , Prenume='" + textBox4.Text + "' , Data='" + dateTimePicker1.Value.ToShortDateString() + "', Proiect='" + textBox1.Text + "', Schimburi='" + label10.Text + "', Poza=#Poza, Acord='" + textBox2.Text + "', Baza='" + textBox3.Text + "' WHERE Nume='" + textBox5.Text + "' AND Prenume='" + textBox4.Text + "'";
cmd.CommandText = query;
cmd.ExecuteNonQuery();
MessageBox.Show("Salvat cu succes!");
this.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
Here is how I search data:
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text.Length != 0)
{
var numePrenume = textBox1.Text.Trim().Split(' ');
if (numePrenume.Count() > 1)
{
var nume = numePrenume[0];
var prenume = numePrenume[1];
var connString = (#"Data Source=" + System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) + #"\Angajati.sdf");
using (var conn = new SqlCeConnection(connString))
{
try
{
conn.Open();
var query = "SELECT COUNT(*) FROM info WHERE Nume='" + nume + "' AND Prenume='" + prenume + "'";
var command = new SqlCeCommand(query, conn);
var dataAdapter = new SqlCeDataAdapter(command);
var dataTable = new DataTable();
dataAdapter.Fill(dataTable);
//checks if there's the searched record is in the db.
int infoCount = (int)command.ExecuteScalar();
if (infoCount > 0)
{
Info form = new Info(nume, prenume);
form.Show();
}
else
{
MessageBox.Show("Nu exista un angajat cu acest nume");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
else
{
MessageBox.Show("Nu ai introdus prenumele");
}
}
else
{
MessageBox.Show("Nu ai introdus nici un nume!");
}
}
I have solved this problem by changing the path to the db, it was something wrong at it, and by creating a refresh function for my gridView called after the insert. Bellow is the code for the solution:
Getting the path like this now:
string startPath = Application.StartupPath;
var filepath = startPath + "\\" + "Grupe.sdf";
var connString = (#"Data Source=" + filepath +"");
The refresh function:
public void refresh()
{
var connString = (#"Data Source=" + System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)) + #"\Grupe.sdf");
using (var conn = new SqlCeConnection(connString))
{
try
{
conn.Open();
var query = "SELECT * FROM copii";
var command = new SqlCeCommand(query, conn);
var dataAdapter = new SqlCeDataAdapter(command);
var dataTable = new DataTable();
dataAdapter.Fill(dataTable);
dataGridView1.DataSource = dataTable;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}

Textbox value does not get updated in asp.net

I have some Textboxes in my page. I am getting values from Database in and updating Textboxes in my page load. I have a code to update values in database behind update button. the problem is that when I change the textbox value and click update button, the value in textbox is again the original one. It retains its value. My code is
protected void Page_Load(object sender, EventArgs e)
{
int id = Convert.ToInt32(Session["DocumentID"]);
Connection conn = new Connection();
string query = "SELECT * from Document where DocumentID='" + id + "'";
SqlCommand sqlcom = new SqlCommand(query, conn.conopen());
SqlDataAdapter daexp = new SqlDataAdapter(sqlcom);
System.Data.DataTable dtexp = new System.Data.DataTable();
daexp.Fill(dtexp);
TextBox1.Text = dtexp.Rows[0][1].ToString();
TextBox3.Text = dtexp.Rows[0][2].ToString();
TextBox6.Text = dtexp.Rows[0][3].ToString();
TextBox4.Text = dtexp.Rows[0][4].ToString();
TextBox5.Text = dtexp.Rows[0][5].ToString();
TextBox7.Text = dtexp.Rows[0][6].ToString();
TextBox7.ReadOnly = true;
}
protected void Button1_Click(object sender, EventArgs e)
{
int id = Convert.ToInt32(Session["DocumentID"].ToString());
if (FileUpload1.HasFile)
{
HttpPostedFile Image = FileUpload1.PostedFile;
string contentType = Image.ContentType;
if (contentType.Equals("application/octet-stream"))
{
contentType = "application/pdf";
}
else if (contentType.Equals("application/vnd.openxmlformats-officedocument.wordprocessingml.document"))
{
contentType = "application/msword";
}
int nFileLen = Image.ContentLength;
byte[] myData = new byte[nFileLen];
Image.InputStream.Read(myData, 0, nFileLen);
Connection con = new Connection();
con.conopen();
string query = "UPDATE Document SET Setup='" + TextBox1.Text + "', ReferenceNO='" + TextBox3.Text + "', DocumentDate='" + TextBox6.Text + "', Subject='" + TextBox4.Text + "', NameOfInitiator='" + TextBox5.Text + "', Document=#Doc, FolderID='" + DropDownList1.Text + "', DocTypeID='" + DropDownList4.Text + "', DirectorateID='" + DropDownList3.Text + "', OrganizationID='" + DropDownList2.Text + "' WHERE DocumentID='" + id + "'";
SqlCommand sqlcom = new SqlCommand(query, con.conopen());
sqlcom.Parameters.AddWithValue("#Doc", myData);
sqlcom.ExecuteNonQuery();
Label12.Text = "Document Updated Successfully";
Label12.ForeColor = System.Drawing.Color.Green;
Label12.Visible = true;
Label12.Text = "Document Updated Successfully";
Label12.ForeColor = System.Drawing.Color.Green;
Label12.Visible = true;
}
else
{
Connection conn = new Connection();
string query = "UPDATE Document SET Setup='" + TextBox1.Text + "', ReferenceNO='" + TextBox3.Text + "', DocumentDate='" + TextBox6.Text + "', Subject='" + TextBox4.Text + "', NameOfInitiator='" + TextBox5.Text + "', FolderID='" + DropDownList1.Text + "', DocTypeID='" + DropDownList4.Text + "', DirectorateID='" + DropDownList3.Text + "', OrganizationID='" + DropDownList2.Text + "' WHERE DocumentID='" + id + "'";
SqlCommand sqlcom = new SqlCommand(query, conn.conopen());
sqlcom.ExecuteNonQuery();
}
}
You are updating the values of Textboxes from database in your Page_Load. Every time page is posted back it gets values from database and sets in TextBoxes. You need to add a check and only update values and set to TextBoxes if page is loaded first time and not posted back. Like this:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
//your code here...
}
}
I know: Order Event of asp.net PreInit -Init -InitComplete -PreLoad -LoadPage -Control events -LoadComplete -PreRender -SaveStateComplete -Render -Unload
Therefore , When u onckick button, Webpage will ispostback. after, call pageload -> EventButton. value of textbox change, because your pageload set value for textbox.
Edit code:
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack){
int id = Convert.ToInt32(Session["DocumentID"]);
Connection conn = new Connection();
string query = "SELECT * from Document where DocumentID='" + id + "'";
SqlCommand sqlcom = new SqlCommand(query, conn.conopen());
SqlDataAdapter daexp = new SqlDataAdapter(sqlcom);
System.Data.DataTable dtexp = new System.Data.DataTable();
daexp.Fill(dtexp);
TextBox1.Text = dtexp.Rows[0][1].ToString();
TextBox3.Text = dtexp.Rows[0][2].ToString();
TextBox6.Text = dtexp.Rows[0][3].ToString();
TextBox4.Text = dtexp.Rows[0][4].ToString();
TextBox5.Text = dtexp.Rows[0][5].ToString();
TextBox7.Text = dtexp.Rows[0][6].ToString();
TextBox7.ReadOnly = true;
}
}
Try to refer to the value Attribute:
TextBox1.Attributes("value")

Could not find a part of the path . Update sql using upload buttom

if i choose photo or image with FileUpload control .. The Record Update procees will success but if the FileUpload Control Has no file choosen The Above Error Appear , to keep in mind the path is correct and exists and the FileUpload Control Saves The Picture Without any problem .
protected SqlCommand News_command;
protected SqlDataAdapter News_adp;
protected System.Data.DataTable News_tbl;
protected SqlConnection _connection;
protected string _ID;
protected void Page_Load(object sender, EventArgs e)
{
if ((Request.QueryString["ID"] != null))
{
_ID = Request.QueryString["ID"].ToString();
}
prepareConnection();
News_command.CommandText = "select * from News where ID=#ID";
News_command.Parameters.AddWithValue("ID", _ID);
News_adp = new SqlDataAdapter();
News_tbl = new System.Data.DataTable();
News_adp.SelectCommand = News_command;
News_adp.Fill(News_tbl);
if (News_tbl.Rows.Count > 0)
{
lblID.Text = News_tbl.Rows[0]["ID"].ToString();
titleTextBox.Text = News_tbl.Rows[0]["Title"].ToString();
CKEditor1.Text = News_tbl.Rows[0]["Contect"].ToString();
imgArticle.ImageUrl = News_tbl.Rows[0]["img"].ToString();
lblDate.Text = News_tbl.Rows[0]["Date"].ToString();
}
}
protected void prepareConnection()
{
_connection = new SqlConnection(#"Data Source=Abu-Adam\localhost;Initial Catalog=BrainStorms;User ID=sa;Password=ameer123");
_connection.Open();
News_command = new SqlCommand();
News_command.Connection = _connection;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.PostedFile == null)
{
prepareConnection();
News_command.CommandText = "UPDATE News SET Title=" + "N'" + titleTextBox.Text + "'" + "," + "Contect=" + "N'" + CKEditor1.Text + "'" + " WHERE ID='" + Convert.ToInt16(lblID.Text) + "';";
News_command.ExecuteNonQuery();
}
else if (FileUpload1.PostedFile != null)
{
prepareConnection();
string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
//save file to disk
FileUpload1.SaveAs(Server.MapPath("~/ArticleImages/News/" + FileName));
News_command.CommandText = "UPDATE News SET Title=" + "N'" + titleTextBox.Text + "'" + "," + "Contect=" + "N'" + CKEditor1.Text + "'" + ",img=#FilePath WHERE ID='" + Convert.ToInt16(lblID.Text) + "';";
News_command.Parameters.AddWithValue("FilePath", "~/ArticleImages/News/" + FileName);
try
{
News_command.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
else
{
try
{
News_command.ExecuteNonQuery();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
}
where is the wrong in my code ?? any suggestion please ??
regards
Ameer.
Because as per your code Fileupload never comes null.
Try validating your code:
if(fileUpload.HasFile && fileUpload.PostedFile.ContentLength>0) // check for
validity of file
{
var path = string.Format("~/YourImageDir/{0}",Guid.NewGuid().ToString().
Replace("-",string.Empty));
//then do your update with this above path
}
else
{
// update without file path
}

Button click fires text changed event

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;
}
}
}

Categories