|
|
|
[C#]สอบถามผู้รู้คะ รอบกวนขอโค้ด insert datatable ลง database หน่อยคะ |
|
|
|
|
|
|
|
Code (C#)
SqlConnection objConn = new SqlConnection();
SqlCommand objCmd = new SqlCommand();
String strConnString,strSQL;
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
strSQL = "INSERT INTO customer (CustomerID,Name,Email,CountryCode,Budget,Used) " +
" VALUES " +
" ('" + this.txtCustomerID.Text + "','" + this.txtName.Text + "','" + this.txtEmail.Text + "', " +
" '" + this.txtCountryCode.Text + "','" + this.txtBudget.Text + "','" + this.txtUsed.Text + "')";
objConn.ConnectionString = strConnString;
objConn.Open();
objCmd.Connection = objConn;
objCmd.CommandText = strSQL;
objCmd.CommandType = CommandType.Text;
this.pnlAdd.Visible = false;
try
{
objCmd.ExecuteNonQuery();
this.lblStatus.Text = "Record Inserted";
this.lblStatus.Visible = true;
}
catch (Exception ex)
{
this.lblStatus.Visible = true;
this.lblStatus.Text = "Record can not insert Error ("+ ex.Message +")";
}
objConn.Close();
objConn = null;
|
|
|
|
|
Date :
2016-06-01 10:37:15 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|