这是我到目前为止所拥有的
STP有一些输出和输入参数 这是我到目前为止所拥有的
STP有一些输出和输入参数
答案 0 :(得分:0)
虽然可以使用SqlDataReader,但是这些繁琐的任务有很多代码。使用Linq2SQL并在设计器中点击几下你可以写这个
using (var ed = new MyDataContext())
{
var result = ed.SEARCH_Information(ID, JobType, ImportType);
//do whatever with the strongly typed result...
}
答案 1 :(得分:-1)
首先,你需要调用StoredProcedure。在此示例中,您连接do数据库并使用3个参数调用StoredProcedure,并返回DetailsDtoOBject 要打电话给这个试试这个:
为返回对象创建类
public class DetailsDto
{
public string JobType {get;set;}
public string ImportType {get;set;}
public string Username {get;set;}
public string Password {get;set;}
public string Connection{get;set;}
public string EmailAddress {get;set;}
public string ContactPhone{get;set;}
public string OldPassword{get;set;}
public string Remarks{get;set;}
}
这是一个用于检索日期格式存储过程的代码
using (var sqlConnection1 = new SqlConnection("Your Connection String"))
{
SqlCommand cmd = new SqlCommand();
SqlDataReader reader;
cmd.CommandText = "StoredProcedureName";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = sqlConnection1;
var id = cmd.CreateParameter();
id.DbType = DbType.String;
id.Direction = ParameterDirection.Input;
id.ParameterName = "id";
id.Value = yourTextBox.Text;
cmd.Parameters.Add(id);
var jobtype = cmd.CreateParameter();
jobtype.DbType = DbType.String;
jobtype.Direction = ParameterDirection.Input;
jobtype.ParameterName = "jobtype";
jobtype.Value = yourTextBoxWithJobType.Text;
cmd.Parameters.Add(jobtype);
var importType = cmd.CreateParameter();
importType.DbType = DbType.String;
importType.Direction = ParameterDirection.Input;
importType.ParameterName = "importType";
importType.Value = yourComboBox.SelectedIthem;
cmd.Parameters.Add(importType);
sqlConnection1.Open();
reader = cmd.ExecuteReader();
var result = new List<DetailsDto>();
while (reader.Read()) // Each row from StoredProcedure
{
result.Add(new DetailsDto {
JobType = reader.GetString(0),
ImportType = reader.GetString(1),
Username = reader.GetString(2),
Password = reader.GetString(3),
Connection = reader.GetString(4),
EmailAddress = reader.GetString(5),
ContactPhone = reader.GetString(6),
OldPassword = reader.GetString(7),
Remarks = reader.GetString(8)
});
}
sqlConnection1.Close();
在result
中,您拥有存储过程的所有行。您必须检查SP habe null值的值。