C#将文本框的数据存到SQL数据库

方法一、这种方法只能将文本框、单/多选框的内容存到数据库,不能存照片

 sqlCommand.CommandText =
            $"INSERT tb_DocRecipel(DocReNo,UserNo,UserName,DateTime,DocName,MedName,MedAmount,Specific)"
               + $"VALUES"
               + $"('{this.txtDocReNo.Text.Trim()}','{this.txtUserNo.Text.Trim()}','{this.txtUserName.Text.Trim()}','{this.textBox1.Text.Trim()}','{this.txtDoctorName.Text.Trim()}','{this.cmbMedName.Text.Trim()}','{this.txtMedAmount.Text.Trim()}','{this.txtSpecific.Text.Trim()}');";

方法二:这种方法既能将文本框、单/多选框的内容存到后端数据库,也能将照片存到数据库,当然了,存照片还需写其他的代码,这是在存照片的相关代码写好后,下面的代码可以将照片存到数据库

 sqlCommand.CommandText =
                     $"INSERT tb_Qualification(DoctorNo,DoctorName,DoctorId,dateTime,DoctorYears," +
                     $"DoctorGender,DoctorPhone,DoctorUnitAdd,DoctorPhoto)"
                + "VALUES (@DoctorNo,@DoctorName,@DoctorId,@dateTime,@DoctorYears,@DoctorGender," +
                "@DoctorPhone,@DoctorUnitAdd,@DoctorPhoto)";
            sqlCommand.Parameters.AddWithValue("@DoctorNo", this.txtDoctorNo.Text);
            sqlCommand.Parameters.AddWithValue("@DoctorName", this.txtDoctorName.Text);
            sqlCommand.Parameters.AddWithValue("@DoctorId", this.txtDoctorId.Text);
            sqlCommand.Parameters.AddWithValue("@dateTime", this.txtBirth.Text);
            sqlCommand.Parameters.AddWithValue("@DoctorYears", this.txtYears.Text);
            sqlCommand.Parameters.AddWithValue("@DoctorGender", this.txtGender.Text);
            sqlCommand.Parameters.AddWithValue("@DoctorPhone", this.txtDoctorPhone.Text);
            sqlCommand.Parameters.AddWithValue("@DoctorUnitAdd", this.txtWorkAddress.Text);
            sqlCommand.Parameters.AddWithValue("@DoctorPhoto", DoctorphotoBytes);

你可能感兴趣的:(C#将文本框的数据存到SQL数据库)