|
|
|
error " Record can not insert Error (Object reference not set to an instance of an object.)" ??? |
|
|
|
|
|
|
|
ขอมูลทั้งหมดลง db นะครับ เเต่มัน เกิด error ขึ้นจะเเก้ยังไงครับ ??
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebApp
{
public partial class CreateMeet : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Calendar1_SelectionChanged1(object sender, EventArgs e)
{
this.TextDate.Text = "" + this.Calendar1.SelectedDate;
}
protected void Button1_Click(object sender, EventArgs e)
{
if (!this.FileUpload1.HasFile)
{
this.lblStatus.Text = "Please select upload file!";
}
else
{
this.FileUpload1.SaveAs(Server.MapPath("Myfile/" + FileUpload1.FileName));
this.lblStatus.Text = "<b>" + FileUpload1.FileName + "</b> Uploaded.<br>";
SqlConnection objConn;
SqlCommand objCmd;
String strConnString, strSQL;
strConnString = "Server=localhost;UID=sa;PASSWORD=12345;database=mydatabase;Max Pool Size=400;Connect Timeout=600;";
objConn = new SqlConnection(strConnString);
objConn.Open();
strSQL = "INSERT INTO Createmeet (MeetID,NameMeet,TypeMeet,Date,Time,Location,files) " +
" VALUES " +
" ('" + this.TextBoxID.Text + "','" + this.TextNM.Text + "','" + this.DropDownListTypeMeet.SelectedItem + "', " +
" '" + this.TextDate.Text + "','" + this.DropDownListTime.SelectedItem + "','" + this.DropDownListRM.SelectedItem + "','" + FileUpload1.FileName + "')";
objCmd = new SqlCommand();
objCmd.Connection = objConn;
objCmd.CommandType = CommandType.Text;
objCmd.CommandText = strSQL;
objCmd.ExecuteNonQuery();
objCmd = null;
objConn.Close();
objConn = null;
try
{
objCmd.ExecuteNonQuery();
Response.Redirect("ListMeet.aspx");
}
catch (Exception ex)
{
this.lblStatus.Visible = true;
this.lblStatus.Text = "Record can not insert Error (" + ex.Message + ")";
}
}
}
}
}
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), C#
|
|
|
|
|
|
Date :
2012-12-20 15:03:08 |
By :
Kaen17 |
View :
892 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
บรรทัดที่ 60 เลย
ปิด connection ไปแล้ว จะมาเรียก objCmd.ExecuteNonQuery() ซ้ำอีกทำไม
|
|
|
|
|
Date :
2012-12-20 15:54:23 |
By :
ห้ามตอบเกินวันละ 2 กระทู้ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แฮะ ๆ ขอบคุณครับ "ต้องฝึกอีกเยอะเลยผม"
|
|
|
|
|
Date :
2012-12-20 16:03:09 |
By :
Kaen17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|