using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Text;namespace ConsoleApplication1 { class Data { public static void Main() { string strCon = @"server=(local);uid=sa;password=sa;database=db"; SqlConnection con = new SqlConnection( strCon ); con.Open(); /*SqlCommand com = new SqlCommand(); com.CommandText = "test"; com.CommandType = CommandType.StoredProcedure; com.Connection = con; SqlParameter p = new SqlParameter( "@returnvalue", SqlDbType.Int, 4, ParameterDirection.Output, false, 0, 0, string.Empty, DataRowVersion.Default, null ); SqlParameter pr = new SqlParameter( "@rv", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, 0, 0, string.Empty, DataRowVersion.Default, null ); com.Parameters.Add( p ); com.Parameters.Add( pr );*//* SqlCommand com = new SqlCommand( "select * from SwapBooks where ISBN='34'", con ); SqlDataAdapter sda = new SqlDataAdapter( com ); DataSet ds = new DataSet(); sda.Fill( ds );
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;namespace ConsoleApplication1
{
class Data
{
public static void Main()
{
string strCon = @"server=(local);uid=sa;password=sa;database=db";
SqlConnection con = new SqlConnection( strCon );
con.Open();
/*SqlCommand com = new SqlCommand();
com.CommandText = "test";
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;
SqlParameter p = new SqlParameter( "@returnvalue", SqlDbType.Int, 4, ParameterDirection.Output, false, 0, 0, string.Empty, DataRowVersion.Default, null );
SqlParameter pr = new SqlParameter( "@rv", SqlDbType.Int, 4, ParameterDirection.ReturnValue, false, 0, 0, string.Empty, DataRowVersion.Default, null ); com.Parameters.Add( p );
com.Parameters.Add( pr );*//* SqlCommand com = new SqlCommand( "select * from SwapBooks where ISBN='34'", con ); SqlDataAdapter sda = new SqlDataAdapter( com );
DataSet ds = new DataSet();
sda.Fill( ds );
foreach (DataRow dr in ds.Tables[0].Rows)
{
Console.WriteLine( dr["title"] );
}
//Console.WriteLine( com.Parameters["@returnvalue"].Value );
//Console.WriteLine( com.Parameters["@rv"].Value );
con.Close(); Console.WriteLine( "Ending..." );
Console.ReadLine();
} }
}你只需要把上边的DataSet绑定到GridView就可以了!
上班的注释代码还演示了如何调用存储过程,如何获得存储过程返回值和输出参数!
最基础的东西都有 我就看这两本书入门的