|
public static SqlConnection creatString()//创建连接字符串 { string mystring = "Data Source=5FAF81B03F644F7\\FGFDS;Initial Catalog=wujilin;User ID=sa;Password=222222";
SqlConnection myconnection = new SqlConnection(mystring);
return myconnection; }
public static DataSet givemessage()//无参数 返回一个集合 { DataSet ds = new DataSet(); SqlConnection myconnecting =DB.creatString(); SqlDataAdapter sdr = new SqlDataAdapter("givemessage", myconnecting); sdr.SelectCommand.CommandType = CommandType.StoredProcedure; sdr.Fill(ds);
return ds; } public static DataSet givemessage1(string a)//带输入参数 返回序列集合 { SqlParameter workParam1 = new SqlParameter("@password", SqlDbType.NChar); workParam1.Direction = ParameterDirection.Input; workParam1.Value = a;
SqlDataAdapter sdr = new SqlDataAdapter(); sdr.SelectCommand = new SqlCommand();
sdr.SelectCommand.Connection = DB.creatString(); sdr.SelectCommand.CommandText = "messagexyz"; sdr.SelectCommand.CommandType = CommandType.StoredProcedure; sdr.SelectCommand.Parameters.Add(workParam1);
DataSet ds = new DataSet(); sdr.Fill(ds); return ds; }
public static string singerValue(string m)//返回一个值 { SqlConnection conn = DB.creatString(); SqlCommand mycommand = new SqlCommand("number", conn); mycommand.CommandType = CommandType.StoredProcedure;
SqlParameter workParam; //输入参数 workParam = new SqlParameter("@password", SqlDbType.NChar); workParam.Direction = ParameterDirection.Input; workParam.Value = m; mycommand.Parameters.Add(workParam);
workParam = new SqlParameter("@ItemCount", SqlDbType.Int);//输出参数 workParam.Direction = ParameterDirection.Output; mycommand.Parameters.Add(workParam);
conn.Open(); mycommand.ExecuteNonQuery(); conn.Close();
return mycommand.Parameters["@ItemCount"].Value.ToString(); } }
dataset 与XML
protected void Button3_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); SqlConnection conn = DB.creatString(); SqlDataAdapter sdr = new SqlDataAdapter("select * from test", conn); sdr.Fill(ds); ds.WriteXml(Server.MapPath("test.xml")); //将数据写入xml文件 } protected void Button4_Click(object sender, EventArgs e) { DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath("test.xml"));//从xml文件中读取数据 this.GridView1.DataSource = ds; this.GridView1.DataBind(); }
|