以下代碼片段可能有助於解決我們在此討論的問題。 如果與此主題無關,請忽略此內容。
簡要說明如何使用文章或代碼。類名稱,方法和屬性,任何技巧或提示。代碼
塊應設置爲風格的 「格式化」 是這樣的:
示例代碼
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;
}
要求
的Visual Studio.Net 2005
.Net框架2.0
MS SQL Server 2000數據庫或MS SQL Server 2005 d atabase。
這不是一個普遍的問題。與C#中的ASP.NET web服務交談是一個蛋糕,這很難。 – MusiGenesis 2008-11-20 22:16:34