A simple Case:SqlConnection conn=new SqlConnection("server=localhost;database=northwind;uid=sa;pwd=");
SqlCommand comm=new SqlCommand(); try { comm.CommandText="select top 1 customerid,companyname,contactname ,address from customers where customerid=@id ";
SqlCommand comm=new SqlCommand();
try
{ comm.CommandText="select top 1 customerid,companyname,contactname ,address from customers where customerid=@id ";
comm.Parameters.Add("@id",SqlDbType.Char,20);
comm.Parameters["@id"].Value=this.TextBox1.Text.ToString();
// comm.CommandType=CommandType.Text;
conn.Open();
tra =conn.BeginTransaction();
comm.Transaction=tra;
comm.Connection=conn;
dr=comm.ExecuteReader();
while(dr.Read())
{
show.Text="<font color=red ><b> customerid is "+dr[0]
+"</b></font> ...companyname is "+dr["companyname"]
+"contactname is >"+dr[dr.GetOrdinal("contactname")];
}dr.Close();
tra.Commit();
}
catch(Exception ex)
{
tra.Rollback();
}
finally
{
conn.Close();
}
不过我建议你用webservice