Я использовал форму дизайна материала в формате html и установил EnableEventValidation=false
после нажатия кнопки save
, чтобы сохранить данные на сервере SQL, однако на сервере SQL сохранены пустые данные
<div class="form">
<h1>Patient Information</h1>
<div class="form-group">
<input type="text" runat="server" id="Fname" required="required" />
<label for="input" class="control-label">First Name</label><i class="bar"></i>
</div>
<div class="form-group">
<input type="text" runat="server" id="Lname" required="required" />
<label for="input" class="control-label">Last Name</label><i class="bar"></i>
</div>
<div class="form-group">
<input type="text" runat="server" id="Address" required="required" />
<label for="input" class="control-label">Address</label><i class="bar"></i>
</div>
<div class="form-group">
<input type="text" runat="server" id="city" required="required" />
<label for="input" class="control-label">City</label><i class="bar"></i>
</div>
<div class="form-group">
<select runat="server" id="gender">
<option>Male</option>
<option>Female</option>
</select>
<label for="select" class="control-label">Gender</label><i class="bar"></i>
</div>
<div class="form-group">
<label class="label-input100" for="date">Date Of Birth</label>
<input type="date" id="birth" runat="server" name="datePurchase" />
</div>
<div class="form-group">
<input type="text" runat="server" id="ssec" required="required" />
<label for="input" class="control-label">Social Security</label><i class="bar"></i>
</div>
<div class="form-group">
<select runat="server" id="inppSel">
</select>
<input runat="server" type="hidden" style="color: red;" id="inpTxt" />
<label for="select" class="control-label">Patient Case</label><i class="bar"></i>
</div>
<div class="button-container">
<button onserverclick="save" type="submit" class="button" id="addnew" runat="server"><span>Submit</span></button>
</div>
</div>
C #:
DataBaseConnection db = new DataBaseConnection();
db.disconnect();
string sql1 = "INSERT INTO TBL_Persons VALUES( @First_Name, @Last_Name, @Address, @City)";
SqlCommand cmd1 = new SqlCommand(sql1, db.connect());
cmd1.Parameters.AddWithValue("@First_Name", Fname.Value);
cmd1.Parameters.AddWithValue("@Last_Name", Lname.Value);
cmd1.Parameters.AddWithValue("@Address", Address.Value);
cmd1.Parameters.AddWithValue("@City", city.Value);
cmd1.ExecuteNonQuery();
string sql2 = "INSERT INTO TBL_Patients VALUES(@Gender, @Date_OF_Birth, @Social_Security, @Person_ID, @Case_ID)";
db.disconnect();
string sql3 = "SELECT MAX(Person_ID) FROM TBL_Persons ";
SqlCommand cmd2 = new SqlCommand(sql3, db.connect());
int max = (int)(cmd2.ExecuteScalar());
db.disconnect();
SqlCommand cmd3 = new SqlCommand(sql2, db.connect());
cmd3.Parameters.AddWithValue("@Gender", gender.Items[gender.SelectedIndex].Text);
cmd3.Parameters.AddWithValue("@Date_OF_Birth", birth.Value);
cmd3.Parameters.AddWithValue("@Social_Security", ssec.Value);
cmd3.Parameters.AddWithValue("@Person_ID", max);
cmd3.Parameters.AddWithValue("@Case_ID", inpTxt.Value);
cmd3.ExecuteNonQuery();