在没有任何数据时进行无效的读取尝试。 25
privatestringGetConnectionString(){stringcon="server=(local);InitialCatalog=discretem...
private string GetConnectionString()
{ string con = "server=(local);Initial Catalog=discretemats;uid=sa;pwd=";
return con;
}
private void WriteToFile(string path, ref byte[] buff)
{
FileStream newFile = new FileStream(path, FileMode.Create);
newFile.Write(buff, 0, buff.Length);
newFile.Close();
}
private int WriteToDB(string strName, string strType, ref byte[] Buff)
{
int FileID = 0;
SqlConnection mycon = new SqlConnection(GetConnectionString());
SqlDataAdapter myda=new SqlDataAdapter("select * from tblfile",mycon);
myda.MissingSchemaAction=MissingSchemaAction.AddWithKey;
SqlCommandBuilder mycmdb = new SqlCommandBuilder(myda);
DataSet myds;
try
{
mycon.Open();
myds=new DataSet();
myda.Fill(myds,"tblFile");
DataTable mydbl=myds.Tables["tblFile"];
DataRow myrow=mydbl.NewRow();
myrow["FileName"]=strName;
myrow["FileSize"]=Buff.Length;
myrow["FileData"]=Buff;
myrow["FileType"]=strType;
mydbl.Rows.Add(myrow);
myda.Update(myds,"tblFile");
if(!myrow.IsNull("FileID"))
FileID=Convert.ToInt32(myrow["FileID"].ToString());
} 展开
{ string con = "server=(local);Initial Catalog=discretemats;uid=sa;pwd=";
return con;
}
private void WriteToFile(string path, ref byte[] buff)
{
FileStream newFile = new FileStream(path, FileMode.Create);
newFile.Write(buff, 0, buff.Length);
newFile.Close();
}
private int WriteToDB(string strName, string strType, ref byte[] Buff)
{
int FileID = 0;
SqlConnection mycon = new SqlConnection(GetConnectionString());
SqlDataAdapter myda=new SqlDataAdapter("select * from tblfile",mycon);
myda.MissingSchemaAction=MissingSchemaAction.AddWithKey;
SqlCommandBuilder mycmdb = new SqlCommandBuilder(myda);
DataSet myds;
try
{
mycon.Open();
myds=new DataSet();
myda.Fill(myds,"tblFile");
DataTable mydbl=myds.Tables["tblFile"];
DataRow myrow=mydbl.NewRow();
myrow["FileName"]=strName;
myrow["FileSize"]=Buff.Length;
myrow["FileData"]=Buff;
myrow["FileType"]=strType;
mydbl.Rows.Add(myrow);
myda.Update(myds,"tblFile");
if(!myrow.IsNull("FileID"))
FileID=Convert.ToInt32(myrow["FileID"].ToString());
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询