“System.InvalidOperationException”类型的未经处理的异常在 System.Data.dll 中发生
其他信息: ExecuteNonQuery: CommandText 属性尚未初始化
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Drawing;
namespace WindowsFormsApplication9
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
static string path1;
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.Title = "选择一张相片";
open.InitialDirectory = @"E:\少女时代\图片";
open.Filter = "图像格式|*.jpg;*.bmp;*.gif;*.png";
if (open.ShowDialog() == DialogResult.OK)
{
path1 = open.FileName;
textBox1.Text = path1;
Bitmap im = new Bitmap(Image.FromFile(open.FileName), 210, 212);
pictureBox1.Image = im;
}
else
return;
}
private void button2_Click(object sender, EventArgs e)
{
textBox1.Text = path1;
FileStream img = new FileStream(path1, FileMode.Open, FileAccess.Read);
Byte[] imgbyte = new Byte[img.Length];
img.Read(imgbyte, 0, imgbyte.Length);
img = null;
string im = "im into image(img)values('{0}')";
im = string.Format(im
, img);
string constr = @"Data Source=.\sqlexpress;Initial Catalog=sss;Integrated Security=True;Pooling=False";
SqlConnection connection = new SqlConnection(constr);
SqlCommand cmd = connection.CreateCommand();
connection.Open();
cmd.Parameters.Add("@image", SqlDbType.Image).Value = imgbyte;
cmd.ExecuteNonQuery(); //错误代码
connection.Close();
MessageBox.Show("保存成功!");
}
}
}

(这个是我建的数据库 不知道对不对)