如何检查序列号是否已被使用

如何检查序列号是否已被使用

本文介绍了如何检查序列号是否已被使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



这篇关于如何检查序列号是否已被使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:17