求一段代码,执行存储过程

zhangsong841 2005-06-09 12:41:07
求一段代码,执行存储过程,类似于
public DataSet GetDataSet(string selectCmd) // Select From Table
{
DataSet ds = null;
SqlConnection m_SqlConnection = new SqlConnection(m_dbConnection);
SqlDataAdapter m_SqlDataAdapter = new SqlDataAdapter(selectCmd,m_SqlConnection);
try
{
ds = new DataSet();
m_SqlDataAdapter.Fill(ds,"Table0");
} // end try
catch (Exception e)
{
throw new Exception("Error in CCPUCode:GetDataSet()-> " + e.ToString());
}
finally
{
m_SqlDataAdapter.Dispose();
m_SqlConnection.Close();
m_SqlConnection.Dispose();
}
return ds;
} // end GetDataSet
要能输入参数的那种
...全文
93 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunnystar365 2005-06-09
  • 打赏
  • 举报
回复
我上面的连接字符串没有写
private string conStr;
private SqlConnection con;
private SqlDataAdapter cmdAdp;
public ComInfo()
{
//
// TODO: 在此处添加构造函数逻辑
//
conStr=System.Configuration.ConfigurationSettings.AppSettings["conn"].ToString();
con=new SqlConnection(conStr);
cmdAdp=new SqlDataAdapter();
}
sunnystar365 2005-06-09
  • 打赏
  • 举报
回复
返回DataSet
public DataSet GetComInfoByID(int classid)
{
SqlCommand cmd=new SqlCommand("COM_INFOBYID",con);
cmd.CommandType=CommandType.StoredProcedure;

SqlParameter parClassID=new SqlParameter("@classid",SqlDbType.Int);
parClassID.Value=classid;
cmd.Parameters.Add(parClassID);

cmdAdp.SelectCommand=cmd;
DataSet ds=new DataSet();
con.Open();
cmdAdp.Fill(ds);
con.Close();
return ds;
}
sunnystar365 2005-06-09
  • 打赏
  • 举报
回复
新增
public bool InsertComInfo(int userid,int classid,string company,string phone,string fax,string contact,string handset,string address,
string zipcode,string email,string homepage,string imageurl)
{
SqlCommand cmd=new SqlCommand("INSERTCOM_INFO",con);
cmd.CommandType=CommandType.StoredProcedure;

SqlParameter parID=new SqlParameter("@userid",SqlDbType.Int);
parID.Value=userid;

SqlParameter parClassID=new SqlParameter("@classid",SqlDbType.Int);
parClassID.Value=classid;

SqlParameter parCompany=new SqlParameter("@company",SqlDbType.VarChar,30);
parCompany.Value=company;

SqlParameter parPhone=new SqlParameter("@phone",SqlDbType.VarChar,20);
parPhone.Value=phone;

SqlParameter parFax=new SqlParameter("@fax",SqlDbType.VarChar,20);
parFax.Value=fax;

SqlParameter parContact=new SqlParameter("@contact",SqlDbType.VarChar,30);
parContact.Value=contact;

SqlParameter parHandSet=new SqlParameter("@handset",SqlDbType.VarChar,20);
parHandSet.Value=handset;

SqlParameter parAddress=new SqlParameter("@address",SqlDbType.VarChar,50);
parAddress.Value=address;

SqlParameter parZipCode=new SqlParameter("@zipcode",SqlDbType.VarChar,10);
parZipCode.Value=zipcode;

SqlParameter parEmail=new SqlParameter("@email",SqlDbType.VarChar,30);
parEmail.Value=email;

SqlParameter parHomePage=new SqlParameter("@homepage",SqlDbType.VarChar,30);
parHomePage.Value=homepage;

SqlParameter parImageUrl=new SqlParameter("@imageurl",SqlDbType.VarChar,70);
parImageUrl.Value=imageurl;

cmd.Parameters.Add(parID);
cmd.Parameters.Add(parClassID);
cmd.Parameters.Add(parCompany);
cmd.Parameters.Add(parPhone);
cmd.Parameters.Add(parFax);
cmd.Parameters.Add(parContact);
cmd.Parameters.Add(parHandSet);
cmd.Parameters.Add(parAddress);
cmd.Parameters.Add(parZipCode);
cmd.Parameters.Add(parEmail);
cmd.Parameters.Add(parHomePage);
cmd.Parameters.Add(parImageUrl);
con.Open();
int result=cmd.ExecuteNonQuery();
con.Close();
if(result>0)
{
return true;
}
else
{
return false;
}
}
lr2651 2005-06-09
  • 打赏
  • 举报
回复
public DataSet GetDataSet(string 存储过程名) // Select From Table
{
DataSet ds = null;
SqlConnection m_SqlConnection = new SqlConnection(m_dbConnection);
SqlDataAdapter m_SqlDataAdapter = new SqlDataAdapter();
m_SqlDataAdapter.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
m_SqlDataAdapter.SelectCommand.CommandText = "存储过程名";
m_SqlDataAdapter.SelectCommand.Connection = m_SqlConnection;
try
{
ds = new DataSet();
m_SqlDataAdapter.Fill(ds,"Table0");
} // end try
catch (Exception e)
{
throw new Exception("Error in CCPUCode:GetDataSet()-> " + e.ToString());
}
finally
{
m_SqlDataAdapter.Dispose();
m_SqlConnection.Close();
m_SqlConnection.Dispose();
}
return ds;
} // end GetDataSet
lr2651 2005-06-09
  • 打赏
  • 举报
回复
public DataSet GetDataSet(string selectCmd) // Select From Table
{
DataSet ds = null;
SqlConnection m_SqlConnection = new SqlConnection(m_dbConnection);
SqlDataAdapter m_SqlDataAdapter = new SqlDataAdapter();
m_SqlDataAdapter.SelectCommand.CommandType = System.Data.CommandType.StoredProcedure;
m_SqlDataAdapter.SelectCommand.CommandText = "存储过程名";
m_SqlDataAdapter.SelectCommand.Connection = m_SqlConnection;
try
{
ds = new DataSet();
m_SqlDataAdapter.Fill(ds,"Table0");
} // end try
catch (Exception e)
{
throw new Exception("Error in CCPUCode:GetDataSet()-> " + e.ToString());
}
finally
{
m_SqlDataAdapter.Dispose();
m_SqlConnection.Close();
m_SqlConnection.Dispose();
}
return ds;
} // end GetDataSet
zhangsong841 2005-06-09
  • 打赏
  • 举报
回复
结果放在dataset中

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧