Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
i need to use username and password in crystal report and
i pass value from dataGridView to the store procedure


the store procedure is:
SQL
Create proc [dbo].[PrintCatCustomersTbl]
@catId int
as
select catId,catName,catNote from CatCustomersTbl where catId=@catId





and this is my code to print from dataGridView:

C#
Report.ReportCatProductsSingle reportcustomer = new Report.ReportCatProductsSingle();
 reportcustomer.SetParameterValue("@catId",this.dataGridView1.CurrentRow.Cells[0]
.Value.ToString());
            Report.FormCatProducts fmct = new Report.FormCatProducts();
          
            fmct.crystalReportViewer1.ReportSource = reportcustomer;
            fmct.ShowDialog();




Can i use the dataset to use the UserName and Password and Print from dataGridView
Like This:

C#
string DatabaseServer = ConfigurationManager.AppSettings["Server"];
            string userId = ConfigurationManager.AppSettings["Userid"];
            string Password = ConfigurationManager.AppSettings["Password"];
            string DataBaseName = ConfigurationManager.AppSettings["DataBase"];
Posted
Updated 27-Mar-15 10:27am
v2
Comments
What is the issue here? You just need to build the connection string and then connect to the database and get the records and bind.
Maciej Los 28-Mar-15 13:49pm    
You did not provide enough information about your issue, but...

On the first look, you pass wrong data into SP, because SP expects integer data 1), but you pass string 2).



1) @catId int
2) "@catId",this.dataGridView1.CurrentRow.Cells[0].Value.ToString()

1 solution

You can try this way:

DataTable dt = new DataTable();


for (int i=0;i<yourgridviewname.rows.count;i++)
{
//To get the Paramater of the stored procedure from Grid view
string catId = YourGridViewName.Items[i].Text;

SqlCommand cmd = new SqlCommand("PrintCatCustomersTbl", conn);
cmd.Parameters.Add("@catId", SqlDbType.int).Value =catId;
cmd.CommandType = CommandType.StoredProcedure;
SqlDataAdapter adp = new SqlDataAdapter(cmd);
adp.Fill(dt);
///// you can also here get your the data row by row/////
}
// to display the list of data returned from the stored procedure
AnyControlName.DataSource = dt;
AnyControlName.DataBind();
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900