我已经彻底搜索了整个访问被拒绝的问题,并没有在我自己的系统上找到任何与访问 Windows 窗体有关的问题,所有问题都与 Web 应用程序有关。
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
byte[] imgdata;
FileStream fsrw;
string fname;
openFileDialog1.Filter = "Sai Files(*.JPG;*.GIF)|*.jpg;*.gif|All files (*.*)|*.*";
openFileDialog1.ShowDialog();//opens the dialog box
fname = openFileDialog1.FileName;//stores the file name in fname
pictureBox1.ImageLocation = fname;//gives the image location to picturebox
fsrw = new FileStream("C:\\Users\\Sainath\\Desktop", FileMode.Open, FileAccess.ReadWrite);
imgdata = new byte[fsrw.Length];
fsrw.Read(imgdata, 0, Convert.ToInt32(fsrw.Length));
fsrw.Close();
string s = "insert into imagetest values(@p1,@p2)";
SqlConnection con = new SqlConnection("server=.;Data Source=.;Initial Catalog=Work;Integrated Security=True");
SqlCommand cmd = new SqlCommand(s, con);
cmd.Parameters.AddWithValue("@p1", imgdata);
cmd.Parameters.AddWithValue("@p2", fname);
con.Open();
int i = cmd.ExecuteNonQuery();
con.Close();
Console.WriteLine(i);
}
}