| |

VerySource

 Forgot password?
 Register
Search
View: 1032|Reply: 5

c # call stored procedure !!! help !!!

[Copy link]

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-1-23 12:20:01
| Show all posts |Read mode
Brothers help! Find a stored procedure and call the stored procedure (distribution function) code!
The function simultaneously receives the DataSet returned by the stored procedure and the number of records selected!
Reply

Use magic Report

0

Threads

29

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-2-6 17:00:02
| Show all posts
public DataSet filmdetails (int id)
{
SqlCommand Command = new SqlCommand (connection);
SqlParameter filmID = new SqlParameter ("@ MovieID", SqlDbType.Int);
filmID.Value = id;
Command.Parameters.Add (filmID);
Command.CommandText = "select_FilmDetails";
Command.CommandType = CommandType.StoredProcedure;
DataSet ds = new DataSet ();
DataAdapter da = ...;
.............................
da.fill (ds);
return ds;
}

Setting up stored procedures lies in these two sentences
Command.CommandText = "select_FilmDetails"; // The name of the stored procedure
Command.CommandType = CommandType.StoredProcedure; // Description command is a stored procedure in sqlserver
// Add parameters
SqlParameter filmID = new SqlParameter ("@ MovieID", SqlDbType.Int);
filmID.Value = id;
Command.Parameters.Add (filmID);

As for returning select records, you can set a read-only public property in the class
private int count
public int countRow
{
   get
{
   return count;
}
}

Use a function to get a DataSet to access records using only the attribute. You can also use the ref modifier. However, general object operations can still use method and property members. Simplicity is better
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-2-6 18:15:01
| Show all posts
The kind brother above! Can it be more complete? My dish! !! I beg you! !! !! !! !!
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-7 01:30:01
| Show all posts
Use SQLHelper, it is quite easy to use.
Reply

Use magic Report

0

Threads

1

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

Post time: 2020-2-7 16:15:01
| Show all posts
// you do this
public DataSet filmdetails (int id)
{
SqlCommand Command = new SqlCommand ("select_FilmDetails", connection);
Command.CommandType = CommandType.StoredProcedure;
SqlParameter filmID = new SqlParameter ("@ MovieID", SqlDbType.Int);
filmID.Value = id;
Command.Parameters.Add (filmID);
DataAdapter da = new DataAdapter (Command);
DataSet ds = new DataSet ();
da.fill (ds);
return ds;
}
Reply

Use magic Report

2

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

 Author| Post time: 2020-2-8 11:30:01
| Show all posts
ALTER PROCEDURE [dbo]. [PageList]
(
    @PageSize int,-records per page
    @PageIndex int,-the current number of pages, starting at 1
    @Condition varchar (8000),-query conditions, including and, where, must have a condition such as where 2> 1
    @TheTable varchar (8000), --table name
    @SelectField varchar (8000),-the field to be selected
    @OrderBy varchar (8000), --OrderBy, including order
    @TableID varchar (8000) --table primary key
)
AS
begin
declare @Sql varchar (8000)
 
--Return record
set @ Sql = 'select top' + cast (@PageSize as varchar (10)) + '' + @SelectField + 'from' + @TheTable + '' + @Condition + 'and'
    + @TableID + 'not in (select top' + cast ((@ PageSize * (@ PageIndex-1)) as varchar (10)) + '' + @ TableID + 'from' + @TheTable + '' + @Condition
    + '' + @OrderBy + ')' + @OrderBy
exec (@sql)
 
--- return total
set @ Sql = 'select count (' + @TableID + ') from' + @TheTable + '' + @Condition
exec (@sql)
end
How to call such a stored procedure with C #! Return both recordsets and totals? Online etc
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list