getting last inserted row
-
Hi, we r developing visitor tracking system,when avisitor come giving a card and he swips and enters inside ,when he releaving handovers the card to watchmen.after that there is a chance same card can be given to someother visitor. mysql table is not having primary key. table is like this: cardid name intime outtime -------------------------------------------- 123 raj 1/2/2014 10:12 1/2/2014 11:00 234 rajee 1/2/2014 10:34 123 vani 1/2/2014 12:10 then here how can i get the last inserted row of id(123) to update the outtime am using c# following code:
String intime = "";
String outtime = "";String indatetime=System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); String outdatetime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); using (MySqlConnection con = new MySqlConnection(ConnectionString)) { String query = "select \* from visitor where card\_id=@id ORDER BY card\_id DESC LIMIT 1"; MySqlCommand command = new MySqlCommand(query, con); command.Parameters.AddWithValue("@id", txtAddVisitorCardId.Text); con.Open(); using (MySqlDataReader rdr = command.ExecuteReader()) { if (rdr.Read()) { intime = rdr\["in\_time"\].ToString(); outtime = rdr\["out\_time"\].ToString(); } } } if (((intime == "") && (outtime == "")) || ((intime!="")&&(outtime !=""))) { using (MySqlConnection con = new MySqlConnection(ConnectionString)) { String query = "insert into visitor(card\_id,name,age,address,id\_proof,contact\_person,purpose,in\_time) values(@id,@name,@age,@address,@idproof,@contact,@purpose,@in)"; MySqlCommand command = new MySqlCommand(query, con); command.Parameters.AddWithValue("@id", txtAddVisitorCardId.Text); command.Parameters.AddWithValue("@name", txtAddVisitorName.Text); command.Parameters.AddWithValue("@age", txtAddVisitorAge.Text); command.Parameters.AddWithValue("@address", txtAddVisitorAddress.Text);
-
Hi, we r developing visitor tracking system,when avisitor come giving a card and he swips and enters inside ,when he releaving handovers the card to watchmen.after that there is a chance same card can be given to someother visitor. mysql table is not having primary key. table is like this: cardid name intime outtime -------------------------------------------- 123 raj 1/2/2014 10:12 1/2/2014 11:00 234 rajee 1/2/2014 10:34 123 vani 1/2/2014 12:10 then here how can i get the last inserted row of id(123) to update the outtime am using c# following code:
String intime = "";
String outtime = "";String indatetime=System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); String outdatetime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); using (MySqlConnection con = new MySqlConnection(ConnectionString)) { String query = "select \* from visitor where card\_id=@id ORDER BY card\_id DESC LIMIT 1"; MySqlCommand command = new MySqlCommand(query, con); command.Parameters.AddWithValue("@id", txtAddVisitorCardId.Text); con.Open(); using (MySqlDataReader rdr = command.ExecuteReader()) { if (rdr.Read()) { intime = rdr\["in\_time"\].ToString(); outtime = rdr\["out\_time"\].ToString(); } } } if (((intime == "") && (outtime == "")) || ((intime!="")&&(outtime !=""))) { using (MySqlConnection con = new MySqlConnection(ConnectionString)) { String query = "insert into visitor(card\_id,name,age,address,id\_proof,contact\_person,purpose,in\_time) values(@id,@name,@age,@address,@idproof,@contact,@purpose,@in)"; MySqlCommand command = new MySqlCommand(query, con); command.Parameters.AddWithValue("@id", txtAddVisitorCardId.Text); command.Parameters.AddWithValue("@name", txtAddVisitorName.Text); command.Parameters.AddWithValue("@age", txtAddVisitorAge.Text); command.Parameters.AddWithValue("@address", txtAddVisitorAddress.Text);
-
i want the query plz help
-
Hi, we r developing visitor tracking system,when avisitor come giving a card and he swips and enters inside ,when he releaving handovers the card to watchmen.after that there is a chance same card can be given to someother visitor. mysql table is not having primary key. table is like this: cardid name intime outtime -------------------------------------------- 123 raj 1/2/2014 10:12 1/2/2014 11:00 234 rajee 1/2/2014 10:34 123 vani 1/2/2014 12:10 then here how can i get the last inserted row of id(123) to update the outtime am using c# following code:
String intime = "";
String outtime = "";String indatetime=System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); String outdatetime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); using (MySqlConnection con = new MySqlConnection(ConnectionString)) { String query = "select \* from visitor where card\_id=@id ORDER BY card\_id DESC LIMIT 1"; MySqlCommand command = new MySqlCommand(query, con); command.Parameters.AddWithValue("@id", txtAddVisitorCardId.Text); con.Open(); using (MySqlDataReader rdr = command.ExecuteReader()) { if (rdr.Read()) { intime = rdr\["in\_time"\].ToString(); outtime = rdr\["out\_time"\].ToString(); } } } if (((intime == "") && (outtime == "")) || ((intime!="")&&(outtime !=""))) { using (MySqlConnection con = new MySqlConnection(ConnectionString)) { String query = "insert into visitor(card\_id,name,age,address,id\_proof,contact\_person,purpose,in\_time) values(@id,@name,@age,@address,@idproof,@contact,@purpose,@in)"; MySqlCommand command = new MySqlCommand(query, con); command.Parameters.AddWithValue("@id", txtAddVisitorCardId.Text); command.Parameters.AddWithValue("@name", txtAddVisitorName.Text); command.Parameters.AddWithValue("@age", txtAddVisitorAge.Text); command.Parameters.AddWithValue("@address", txtAddVisitorAddress.Text);
Reposts are bad behavior. how get latest recordfrom mysql table[^]
-
i want the query plz help
Write your own code!
Never underestimate the power of human stupidity RAH