110,502
社区成员
发帖
与我相关
我的任务
分享
private void btnInputMarcateFile_Click(object sender, EventArgs e)
{
openFileDialogOne.AddExtension = true;
openFileDialogOne.CheckFileExists = true;
openFileDialogOne.CheckPathExists = true;
openFileDialogOne.DefaultExt = "*.*";
openFileDialogOne.FileName = "";
if (openFileDialogOne.ShowDialog(this)==DialogResult.OK)
{
System.IO.FileStream fs = new System.IO.FileStream(this.openFileDialogOne.FileName, System.IO.FileMode.Open);
byte[] fileByte = new byte[fs.Length];
System.IO.BinaryReader br = new System.IO.BinaryReader(fs);
fileByte = br.ReadBytes(Convert.ToInt32(fs.Length));
int lastSplit = 0;
fs.Close();
lastSplit= this.openFileDialogOne.FileName.LastIndexOf('\\');
this.openFileDialogOne.FileName= this.openFileDialogOne.FileName.Substring(lastSplit + 1);
string sqlconn = "data source=.;database=bfbc;uid=sa;pwd=sa";
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(sqlconn);
conn.Open();
string sqlStament = "insert into DemarcateRelatingDocument(DemarcateFile,FileName,VehicleConfigureDocument,InputUser,InputTime,EcuFactoryId,Other,Edition) values(@1,@2,@3,@4,@5,@6,@7,@8)";
System.Data.SqlClient.SqlCommand cdm = new System.Data.SqlClient.SqlCommand(sqlStament, conn);
cdm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@1", fileByte));
cdm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@2", this.openFileDialogOne.FileName));
cdm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@3", DateTime.Now.ToLongDateString()));
cdm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@4", "Dahai"));
cdm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@5",DateTime.Now.ToString()));
cdm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@6","WFCYFDJZZC"));
cdm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@7", "无说明信息"));
cdm.Parameters.Add(new System.Data.SqlClient.SqlParameter("@8", 2));
int rtnInt = 0;
rtnInt= cdm.ExecuteNonQuery();
if (rtnInt>0)
{
MessageBox.Show("写入成功!");
}
else
{
MessageBox.Show("写入失败!");
}
conn.Close();
}
}
//定义一个DataReader从数据库读数据用
OleDbDataReader aReader = aCommand.ExecuteReader();
//在控制台输出字符串
Console.WriteLine(This is the returned data from emp_test table);
//如果能读到数据
while(aReader.Read())
{
//控制台输出资料行序数为0的值
Console.WriteLine(aReader.GetInt32(0).ToString());
}