private void CheckSerialNumber() { string strSNExists = ""; openConnection(); MySqlCommand cmd = new MySqlCommand(); cmd.Connection = cn; cmd.CommandType = CommandType.Text; cmd.CommandText = "select Count(*) from AssetManagement where SerialNumber = @SerialNumber"; cmd.Parameters.Add("@SerialNumber", MySqlDbType.VarChar).Value = txtSN.Text; MySqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) { strSNExists = dr.GetChar(strSN).ToString(); } closeConnection(); dr.Close(); if (strSNExists == "") { FileUpload img = (FileUpload)FileUpload1; Byte[] imgByte = null; if (img.HasFile && img.PostedFile != null) { HttpPostedFile File = FileUpload1.PostedFile; imgByte = new Byte[File.ContentLength]; File.InputStream.Read(imgByte, 0, File.ContentLength); } openConnection(); MySqlCommand cmdReg = new MySqlCommand(); cmdReg.Connection = cn; cmdReg.CommandType = CommandType.Text; cmdReg.CommandText = "Insert into AssetManagement (Asset, Component, SerialNumber, Location, UsedBy, ProductPic) values (@Asset, @Component, @SerialNumber, @Location, @UsedBy, @ProductPic)"; cmdReg.Parameters.Add("@Asset", MySqlDbType.VarChar).Value = txtAsset.Text; cmdReg.Parameters.Add("@Component", MySqlDbType.VarChar).Value = txtComponent.Text; cmdReg.Parameters.Add("@SerialNumber", MySqlDbType.VarChar).Value = txtSN.Text; cmdReg.Parameters.Add("@Location", MySqlDbType.VarChar).Value = txtLocation.Text; cmdReg.Parameters.Add("@UsedBy", MySqlDbType.VarChar).Value = txtUsed.Text; cmdReg.Parameters.Add("@ProductPic", MySqlDbType.VarBinary).Value = imgByte; cmdReg.ExecuteNonQuery(); closeConnection(); lblSNExists.Visible = false; } else { lblSNExists.Visible = true; txtSN.Focus(); }
if exists(select * from AssetManagement where SerialNumber = @SerialNumber) begin print 'Exists' //Your Code end else begin print 'Not Exists' // Your Code end
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)