总是提示这个错误 必须声明标量变量 content1,再有想一次批量向数据库1行的3列导入图片二进制流,有啥简单方法吗
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string name = FileUpload1.PostedFile.FileName;
string name1 = FileUpload2.PostedFile.FileName;
string name2 = FileUpload3.PostedFile.FileName;
string name3 = FileUpload4.PostedFile.FileName;
FileStream fs = File.OpenRead(name);
byte[] content = new byte[fs.Length];
fs.Read(content, 0, content.Length);
fs.Close();
FileStream fs1 = File.OpenRead(name1);
byte[] content1 = new byte[fs1.Length];
fs1.Read(content1, 0, content1.Length);
fs1.Close();
FileStream fs2 = File.OpenRead(name2);
byte[] content2 = new byte[fs2.Length];
fs2.Read(content2, 0, content2.Length);
fs2.Close();
FileStream fs3 = File.OpenRead(name3);
byte[] content3 = new byte[fs3.Length];
fs3.Read(content3, 0, content3.Length);
fs3.Close();
string strcon;
strcon = "server='10.30.42.166';database='cyunicom';uid='sa';pwd='lining1983';";
SqlConnection conn = new SqlConnection(strcon);
SqlConnection conn1 = new SqlConnection(strcon);
SqlConnection conn2 = new SqlConnection(strcon);
SqlConnection conn3 = new SqlConnection(strcon);
SqlCommand cmd = conn.CreateCommand();
SqlCommand cmd1 = conn1.CreateCommand();
SqlCommand cmd2 = conn2.CreateCommand();
SqlCommand cmd3 = conn3.CreateCommand();
conn.Open();
conn1.Open();
conn2.Open();
conn3.Open();
cmd.CommandText = "insert into Image (image_id,image_content) values('" + TextBox1.Text + "',@content)";
cmd.CommandType = CommandType.Text;
cmd1.CommandText = "insert into Image (image_content_1) values(@content1) where image_id=" + TextBox1.Text + "";
cmd1.CommandType = CommandType.Text;
cmd2.CommandText = "insert into Image (image_content_2) values(@content2) where image_id = " + TextBox1.Text + "";
cmd2.CommandType = CommandType.Text;
cmd3.CommandText = "insert into Image (image_content_3) values(@content3) where image_id = " + TextBox1.Text + "";
cmd3.CommandType = CommandType.Text;
SqlParameter para = cmd.Parameters.Add("@content", SqlDbType.Image);
para.Value = content;
cmd.ExecuteNonQuery();
SqlParameter para1 = cmd.Parameters.Add("@content1", SqlDbType.Image);
para1.Value =content1;
cmd1.ExecuteNonQuery();
//SqlParameter para2 = cmd.Parameters.Add("@content2", SqlDbType.Image);
// para2.Value =content2;
// cmd2.ExecuteNonQuery();
//SqlParameter para3 = cmd.Parameters.Add("@content3", SqlDbType.Image);
//para3.Value =content3;
//cmd3.ExecuteNonQuery();
conn.Close();
conn1.Close();
conn2.Close();
conn3.Close();
}
}