|
|
|
รบกวนพี่ๆ ช่วยแก้ปัญหาให้ผมหน่อยครับ ว่ามัน Error ตรงไหนครับ |
|
|
|
|
|
|
|
Code (C#)
string strConn;
strConn = WebConfigurationManager.ConnectionStrings["edocConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();
StringBuilder sb = new StringBuilder();
var sqlSave = sb.ToString();
SqlCommand com = new SqlCommand();
com.Connection = Conn;
com.CommandType = CommandType.Text;
com.CommandText = sqlSave;
sb.Clear();
int i;
FileUpload myUpload;
for( i = 1; i <= 5; i++)
{
myUpload = (FileUpload)this.FindControl("FileUpload"+i);
if(myUpload.HasFile)
{
myUpload.SaveAs(Server.MapPath("MyFile/" + myUpload.FileName));
{
sb.Append("INSERT INTO Document(DocID,DepID,DocTitle,DocName,DocTypeID,DocStatusID,PrioID,SpeedID,DocDate,DocUpload,DocFile,EmpNo)");
sb.Append("VALUES (@DocID,@DepID,@DocTitle,@DocName,@DocTypeID,@DocStatusID,@PrioID,@SpeedID,@DocDate,@DocUpload,@DocFile,@EmpNo)");
sqlSave = sb.ToString();
com.CommandText = sqlSave;
com.Parameters.Clear();
com.Parameters.Add("@DocID", SqlDbType.NVarChar).Value = RadTextBox1.Text.Trim();
com.Parameters.Add("@DepID", SqlDbType.Int).Value = RadComboBox1.SelectedValue.ToString();
com.Parameters.Add("@DocTitle", SqlDbType.NVarChar).Value = RadTextBox2.Text.Trim();
com.Parameters.Add("@DocName", SqlDbType.NVarChar).Value = RadTextBox3.Text.Trim();
com.Parameters.Add("@DocTypeID", SqlDbType.Int).Value = RadComboBox5.SelectedValue.ToString();
com.Parameters.Add("@DocStatusID", SqlDbType.Int).Value = RadComboBox4.SelectedValue.ToString();
com.Parameters.Add("@PrioID", SqlDbType.Int).Value = RadComboBox2.SelectedValue.ToString();
com.Parameters.Add("@SpeedID", SqlDbType.Int).Value = RadComboBox3.SelectedValue.ToString();
com.Parameters.Add("@DocDate", SqlDbType.DateTime).Value = RadDatePicker1.SelectedDate.Value.ToShortDateString();
com.Parameters.Add("@DocUpload", SqlDbType.DateTime).Value = DateTime.Today.ToString("dd-MM-yyyy");
com.Parameters.Add("@DocFile", SqlDbType.NVarChar).Value =
com.Parameters.Add("@EmpNo", SqlDbType.NVarChar).Value = "" + Session["No"] + "";
com.ExecuteNonQuery();
Conn.Close();
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), C#
|
|
|
|
|
|
Date :
2012-08-04 22:47:37 |
By :
jakapan |
View :
954 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
var sqlSave = sb.ToString();
ได้ string empty แน่นอน
|
|
|
|
|
Date :
2012-08-05 01:50:45 |
By :
อิอิ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
com.Parameters.Add("@DepID", SqlDbType.Int).Value = RadComboBox1.SelectedValue.ToString();
com.Parameters.Add("@DocTypeID", SqlDbType.Int).Value = RadComboBox5.SelectedValue.ToString();
com.Parameters.Add("@DocStatusID", SqlDbType.Int).Value = RadComboBox4.SelectedValue.ToString();
com.Parameters.Add("@PrioID", SqlDbType.Int).Value = RadComboBox2.SelectedValue.ToString();
com.Parameters.Add("@SpeedID", SqlDbType.Int).Value = RadComboBox3.SelectedValue.ToString();
com.Parameters.Add("@DocDate", SqlDbType.DateTime).Value = RadDatePicker1.SelectedDate.Value.ToShortDateString();
com.Parameters.Add("@DocUpload", SqlDbType.DateTime).Value = DateTime.Today.ToString("dd-MM-yyyy");
type ผิด
Code (C#)
com.Parameters.Add("@EmpNo", SqlDbType.NVarChar).Value = "" + Session["No"] + "";
type ผิด ต้อง cast ก่อน จะใช้ tostring ก็ไม่ผิด
|
|
|
|
|
Date :
2012-08-05 02:15:49 |
By :
อิอิ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|