下面的代码片段可能有助于解决我们在这里讨论的问题。如果它与本主题无关,请忽略它。
简要说明如何使用文章或代码。类名、方法和属性、任何技巧或提示。
代码块应设置为“格式化”样式,如下所示:
示例代码
using System.Data;
using System.Data.Sql
using System.Data.SqlClient;
using System.Web;
using System.Web.Services;
public class FileUploader: System.Web.Services.WebService {
SqlConnection myConnection = new SqlConnection("Data Source=server name ;Initial Catalog=database name; User ID=username; Password='password';");
SqlCommand myCommand = new SqlCommand();
string queryString = "";
public string UploadFile(byte[] f, string fileName)
{
// the byte array argument contains the content of the file
// the string argument contains the name and extension
// of the file passed in the byte array
string nm = data[0];
string sn =data[1];
string bn =data[2];
string st = data[3];
byte img = Convert.Tobyte(img);
myConnection.Open();
queryString = "INSERT INTO tablename(Name,SchemeName,BeneficiarName,Status,Photo)"
+ "VALUES('" + nm + "','" + sn + "','"+ bn +"','" + st + "',@img,')";
myCommand.Parameters.AddWithValue("@img",f);
myCommand.Connection = myConnection;
myCommand.CommandType = CommandType.Text; myCommand.CommandText = queryString; int res = myCommand.ExecuteNonQuery(); myConnection.Close();
if (res > 0)
{
strres = "File Uploaded successfully"; }
else
{
strres = "File not uploaded";
}
return strres;
}
要求
视觉工作室.Net 2005
.Net 框架 2.0
MS SQL Server 2000 数据库或 MS SQL Server 2005 数据库。