我正在设计我的网页 我的代码
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
public void onflbload(object sender,EventArgs e)
{
// Create a byte[] from the input file
int len =flbload.PostedFile.ContentLength;
byte[] pic = new byte[len];
flbload.PostedFile.InputStream.Read (pic , 0, len);
// Insert the image and comment into the database
SqlConnection connection = new SqlConnection( @"Data Source=DEVI\SQLEXPRESS;
Initial Catalog =cat; Integrated Security=SSPI");
try
{
connection.Open ();
SqlCommand cmd = new SqlCommand ("insert into tblphotosetting "
+ "
(BillNo,CustomerName,Address,StartDate,EndDate,Systemurl,Numberofcopies,Amount,Total )
values (@text, @text,@text,@text,@text,@pic,@text,@text,@text)", connection);
cmd.Parameters.Add("@BillNo",TextBox1.Text);
cmd.Parameters.Add("@CustomerName",TextBox2.Text);
cmd.Parameters.Add("@Address",TextBox3.Text);
cmd.Parameters.Add("@StartDate",Rdbsdate.SelectedDate);
cmd.Parameters.Add("@EndDate",Rdbddate.SelectedDate);
cmd.Parameters.Add ("@Systemurl", pic );
cmd.Parameters.Add("@Numberofcopies",TextBox7.Text);
cmd.Parameters.Add("@Amount",TextBox8.Text);
cmd.Parameters.Add("@Total",TextBox9.Text);
cmd.ExecuteNonQuery ();
}
finally
{
connection.Close ();
}
}
}
我的错误图片和记录未存储在我的数据库中
答案 0 :(得分:0)
试试这个
protected void Button1_Click(object sender, EventArgs e)
{
onflbload(sender,e)
}
你可能想这样做
string cmdText = String.Format("insert into tblphotosetting (BillNo,CustomerName,Address,StartDate,EndDate,Systemurl,Numberofcopies,Amount,Total ) values ({0}, {1},{2},{3},{4},{5},{6},{7},{8})",TextBox1.Text,TextBox2.Text,TextBox3.Text,TextBox4.Text,TextBox5.Text,TextBox6.Text,TextBox7.Text,TextBox8.Text,TextBox9.Text);
SqlCommand cmd = new SqlCommand String.Format(cmdText, connection);
cmd.CommandType= CommandType.Text ;
cmd.ExecuteNonQuery ();
答案 1 :(得分:0)
您可以在try {}和finally {}之间插入以下代码吗?所以我们可以在异常中查看问题。
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
答案 2 :(得分:0)
我认为您的插入查询似乎是错误构造的。它应该是 -
"insert into tblphotosetting " + "
(BillNo,CustomerName,Address,StartDate,EndDate,
Systemurl,Numberofcopies,Amount,Total )
values (@BillNo, @CustomerName,@Address,@StartDate,@EndDate,
@Systemurl,@Numberofcopies,@Amount,@Total)"
答案 3 :(得分:0)
这是不对的:
cmd.Parameters.Add("@BillNo",TextBox1.Text);
需要:
cmd.Parameters.Add("@BillNo",sqldbtype.nvarchar).value = TextBox1.Text;
这适用于所有参数。
另外,@ Sachin改变CommandText
SqlCommand
中的参数是正确的