用dataSet.Tables["table"].Rows[0][0].Tostring()就可以得到的
解决方案 »
- 简单问题,请问,这两段代码在性能上有区别吗?
- asp.net登陆页面的代码如何写
- string s = @"abcdefg";,请问这里如何用转义符,string s = @"abc\"defg";这样不行,你试试
- js或正则表达式 替换问题
- js 中的 if else 判断 有个数限制吗(比如有10个if else)
- Calendar 自动刷新
- 询问datagrid动态绑定数据库问题
- 类似华军这类让人下载软件的网站是使用asp.net吗?
- 也许是应该离开的时候了,也许要想想自己的未来了,散分
- 为什么我总是碰到这样的问题:在本机完全正常的东西,传到网站上就不生效了,气死了!
- 怎么设置让用户点击已知的IP地址就能直接访问已做好的程序的index.htm页面?
- 疑惑:关于.net的一个问题(做网站是否适合)
Dim MyConnection As SqlConnection
Dim MyDataAdapter As SqlDataAdapter 'Create a connection to the SQL Server.
MyConnection = New SqlConnection("server=(local);database=pubs;Trusted_Connection=yes") 'Create a DataAdapter, and then provide the name of the stored procedure.
MyDataAdapter = New SqlDataAdapter("GetAuthorsByLastName", MyConnection) 'Set the command type as StoredProcedure.
MyDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure 'Create and add a parameter to Parameters collection for the stored procedure.
MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@au_lname", _
SqlDbType.VarChar, 40)) 'Assign the search value to the parameter.
MyDataAdapter.SelectCommand.Parameters("@au_lname").Value = Trim(txtLastName.Text) 'Create and add an output parameter to Parameters collection.
MyDataAdapter.SelectCommand.Parameters.Add(New SqlParameter("@RowCount", _
SqlDbType.Int, 4)) 'Set the direction for the parameter. This parameter returns the Rows returned.
MyDataAdapter.SelectCommand.Parameters("@RowCount").Direction = ParameterDirection.Output DS = New DataSet() 'Create a new DataSet to hold the records.
MyDataAdapter.Fill(DS, "AuthorsByLastName") 'Fill the DataSet with the rows returned. 'Get the number of rows returned, and then assign it to the Label control.
'lblRowCount.Text = DS.Tables(0).Rows.Count().ToString() & " Rows Found!"
lblRowCount.Text = MyDataAdapter.SelectCommand.Parameters(1).Value & " Rows Found!" 'Set the data source for the DataGrid as the DataSet that holds the rows.
Grdauthors.DataSource = DS.Tables("AuthorsByLastName").DefaultView 'Bind the DataSet to the DataGrid.
'NOTE: If you do not call this method, the DataGrid is not displayed!
Grdauthors.DataBind() MyDataAdapter.Dispose() 'Dispose of the DataAdapter.
MyConnection.Close() 'Close the connection.
SqlParameter[] paras = { new SqlParameter("@a",SqlDbType.Int),
new SqlParameter("@b",SqlDbType.Int),
};
paras[0].Value = a;
paras[1].Direction = ParameterDirection.Output;
int rc = RunSP("sp_GetProductIdByResourceId", paras);
int b = para[1].Value;
DataAccess库中程序的主要部分如下:
// 执行store procedure
protected int RunSP(string procName, SqlParameter[] paras)
{
SqlCommand cmd = CreateCommand(procName,paras);
try {
conn.Open();
cmd.ExecuteNonQuery();
return (int)cmd.Parameters["@_Result"].Value;
}
catch
{
return DATABASEERROR;
}
finally
{
if (conn.State != ConnectionState.Closed)
conn.Close();
}
}protected int RunSP(string procName, SqlParameter[] paras, DataSet ds, string tableName)
{
SqlDataAdapter da = new SqlDataAdapter(CreateCommand(procName,paras));
try {
da.Fill(ds, tableName);
}
catch {
return DATABASEERROR;
}
finally {
if (conn.State != ConnectionState.Closed)
conn.Close();
}
return (int)da.SelectCommand.Parameters["@_Result"].Value;
}// 构建Command对象
private SqlCommand CreateCommand(string procName, SqlParameter[] paras)
{
SqlCommand cmd = new SqlCommand(procName,conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@_Result",SqlDbType.Int);
cmd.Parameters["@_Result"].Direction = ParameterDirection.ReturnValue;
foreach (SqlParameter para in paras)
{
cmd.Parameters.Add(para);
}
return cmd;
}