Ajit N

Ajit N

  • NA
  • 352
  • 71.2k

How to Generate/Print Multiple StudentID from Datagridview ?

Jan 31 2017 6:53 AM
I am working on desktop application. i tried some code for generating id and it will print only one Id at a time.
Now i want to print/generate multiple Id's  based on Roll No  from datagridview.
This is my code...
  1. //this code is used for passing 2 values to GenerateIDCard Form  
  2.         int RollNo;  
  3.         string Class;  
  4.         private void btnGenerateID_Click(object sender, EventArgs e)  
  5.         {  
  6.             foreach (DataGridViewRow rw in dataGridView1.SelectedRows)  
  7.             {  
  8.                 RollNo = Convert.ToInt32(rw.Cells[0].Value);  
  9.                 Class = rw.Cells[2].Value.ToString();  
  10.             }  
  11.             GenerateIDCard generate = new GenerateIDCard(Roll, Class);  
  12.             generate.ShowDialog();  
  13.         }  
 
and this code is used for getting this 2 values which passed from StudentReport Form
  1.          int Getroll;  
  2.         string GetClass;  
  3.         public GenerateIDCard(int RollNo,string Class)  
  4.         {  
  5.             con = new SqlConnection(ConfigurationManager.ConnectionStrings["constr"].ConnectionString);  
  6.             SqlConnection.ClearPool(con);  
  7.             con.Open();  
  8.             InitializeComponent();  
  9.             Getroll = RollNo;  
  10.             GetClass = Class;  
  11.         }  
  12.   
  13.     public void GetStudentInfo()  
  14.         {  
  15.             SqlCommand cmd = new SqlCommand("select Sname,Class,DOB,Mobileno,Address,studimg from StudentRegister where Rollno='"+Getroll+"' and Class='" + GetClass + "'", con);  
  16.             SqlDataReader dr = cmd.ExecuteReader();  
  17.             if (dr.Read())  
  18.             {  
  19.   
  20.                 lblstudentname.Text = dr["Sname"].ToString();  
  21.                 lblstudclass.Text = dr["Class"].ToString();  
  22.                 lbldob.Text = DateTime.Parse(dr["DOB"].ToString()).ToString("dd-MMM-yy");  
  23.                 lblstudentmobile.Text = dr["Mobileno"].ToString();  
  24.                 lblstudentsaddress.Text = dr["Address"].ToString();  
  25.   
  26.                 Studentimage_picname = dr["studimg"].ToString();  
  27.             }  
  28.             dr.Close();  
  29.   
  30.   
  31.             studentpath = "E:\\CoachingClassImages\\StudentIDImages\\" + Studentimage_picname;  
  32.             pictureBoxstudent.Image = new Bitmap(studentpath);  
  33.         }  
 
 So help me how can i do this....

Answers (1)