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);
テーブルコード:
<input runat="server" id="pho" type="file" name="file[]" multiple="" accept="image/*" />
:
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)
);
私は、これはhtmlですデータベースにC#のページから画像を保存したいですどうすればいい? 画像を保存するにはどうすればいいですか?
私は番目のフル・テーブルここ
これを試してみてください:NewUser.Parameters.Add( "@イム"、System.Data.SqlDbType.VarBinary)。 NewUser.Parameters ["@ im"] = image; – jdweng
私は何のイメージを置くべきですか? –
http://stackoverflow.com/questions/744589/how-do-you-store-a-picture-in-anage-column/744603#744603 – Tewr