我在插入一個新的元組到我的表中有麻煩。它不會給出任何錯誤,我不知道爲什麼它不能正常工作。順便說一句TextBox3有這樣的東西:C:\ Temp \ Pic5.jpg。這裏是我的代碼:在c中插入新元組到sql#
protected void Button3_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\MYDB.mdf;Integrated Security=True;User Instance=True");
byte[] data;
try
{
data = System.IO.File.ReadAllBytes(@"" + TextBox3.Text);
string val1 = "" + TextBox1.Text;
string val2 = "" + TextBox2.Text;
string val3 = "" + TextBox3.Text;
SqlCommand cmd = new SqlCommand("Insert INTO Books (Book_Name,Author_Name,Image,In_Lib) VALUES (@BN,@AN,@DATA,@LIB)", con);
cmd.Parameters.AddWithValue("@BN", val1);
cmd.Parameters.AddWithValue("@AN", val2);
cmd.Parameters.AddWithValue("@DATA", val3);
cmd.Parameters.AddWithValue("@LIB", "YES");
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
catch (Exception err)
{
Console.WriteLine(err.Message);
}
}
ASP部分
Book Name:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
Author Name:
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<br />
Image Name:
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button3" runat="server" onclick="Button3_Click" Text="Submit" />
<br />
我的數據庫是這樣的:
- BOOK_NAME VARCHAR(50)
- AUTHOR_NAME VARCHAR(50)
- 圖片圖片
- In_Lib varch AR(50)
控制檯是否可見? –
你能告訴你數據庫表嗎? – Murtaza
該參數的數據類型是什麼? – levi