C#代碼:在sql數據庫中保存圖像如何?
SqlCommand NewUser = new SqlCommand("INSERT INTO [User] Values (@username,@password,@name,@lastname,@location,@profesion,@email,@gender,@money,@pro,@xp,@lv,@m1,@m2,@m3,@m4,@m5,@d1,@d2,@d3,@d4,@d5,@im);", c);
NewUser.Connection = c;
NewUser.Parameters.AddWithValue("@username", txtuser.Text);
NewUser.Parameters.AddWithValue("@password", txtpass.Text);
NewUser.Parameters.AddWithValue("@name", txtFName.Text);
NewUser.Parameters.AddWithValue("@lastname", txtLName.Text);
NewUser.Parameters.AddWithValue("@location", ddlcountry.SelectedItem.Text);
NewUser.Parameters.AddWithValue("@profesion", txtprofession.Text);
NewUser.Parameters.AddWithValue("@email", txtemail.Text);
NewUser.Parameters.AddWithValue("@gender", rbgendere.SelectedItem.Text);
NewUser.Parameters.AddWithValue("@money", 0);
NewUser.Parameters.AddWithValue("@pro", DBNull.Value);
NewUser.Parameters.AddWithValue("@xp", 0);
NewUser.Parameters.AddWithValue("@lv", 1);
NewUser.Parameters.AddWithValue("@m1", 0);
NewUser.Parameters.AddWithValue("@m2", 0);
NewUser.Parameters.AddWithValue("@m3", 0);
NewUser.Parameters.AddWithValue("@m4", 0);
NewUser.Parameters.AddWithValue("@m5", 0);
NewUser.Parameters.AddWithValue("@d1", 0);
NewUser.Parameters.AddWithValue("@d2", 0);
NewUser.Parameters.AddWithValue("@d3", 0);
NewUser.Parameters.AddWithValue("@d4", 0);
NewUser.Parameters.AddWithValue("@d5", 0);
NewUser.Parameters.AddWithValue("@im",);
Session["CurentUserid"] = txtuser.Text;
c.Open();
NewUser.ExecuteNonQuery();
c.Close();
Session["Conect"] = (bool)true;
Response.Redirect("Finish Had Member.aspx", true);
表代碼:
CREATE TABLE [dbo].[User] (
[Username] VARCHAR (100) NOT NULL,
[Pasword] VARCHAR (100) NOT NULL,
[FName] VARCHAR (MAX) NOT NULL,
[LName] VARCHAR (MAX) NOT NULL,
[Location] VARCHAR (MAX) NOT NULL,
[Profesion] VARCHAR (MAX) NOT NULL,
[email] VARCHAR (MAX) NOT NULL,
[gender] VARCHAR (MAX) NOT NULL,
[money] INT NOT NULL,
[property] VARCHAR (MAX) NULL,
[xp] INT NOT NULL,
[level] INT NOT NULL,
[mission1] INT NOT NULL,
[mission2] INT NOT NULL,
[mission3] INT NOT NULL,
[mission4] INT NOT NULL,
[mission5] INT NOT NULL,
[did1] INT NOT NULL,
[did2] INT NOT NULL,
[did3] INT NOT NULL,
[did4] INT NOT NULL,
[did5] INT NOT NULL,
[image] VARBINARY (MAX) NULL,
PRIMARY KEY CLUSTERED ([Username] ASC)
);
我想從C#頁的圖像保存到數據的基礎上這是HTML:
<input runat="server" id="pho" type="file" name="file[]" multiple="" accept="image/*" />
我該怎麼做? 我添加了所有的插入代碼plss loke我如何保存圖像?
我更新代碼有個全表
試試這個:NewUser.Parameters.Add( 「@ IM」,System.Data.SqlDbType.VarBinary); NewUser.Parameters [「@ im」] = image; – jdweng
我應該如何放置圖像? –
http://stackoverflow.com/questions/744589/how-do-you-store-a-picture-in-an-image-column/744603#744603 – Tewr