Click here to Skip to main content
15,920,030 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a data table and i want to pass it to Stored procedure as Parameter, for update the table field and for insert new row.
Can you suggest me.?
Posted
Comments
♥…ЯҠ…♥ 15-Nov-13 1:57am    
why you want to do it like this? you have traditional way of inserting/Updating records in table....
Siva Hyderabad 15-Nov-13 1:57am    
like , this code for row updating...if you have doubt ask me
krranjeet9 15-Nov-13 2:02am    
I have a Datatable which i want to pass to avoid the connection opening and closing.and i want to do insertion at a time
Siva Hyderabad 15-Nov-13 2:05am    
i think u use 3 tier arthitecture, yes?

C#
DataTable dt = new DataTable();
     TextBox txtdat = (TextBox)GVHolidays.Rows[e.RowIndex].Cells[1].Controls[1];
     TextBox txtreason = (TextBox)GVHolidays.Rows[e.RowIndex].Cells[3].Controls[1];
     //int st = Convert.ToInt32(GVHolidays.DataKeys[e.RowIndex].Values[0].ToString());
     objHRPL.status = Convert.ToInt32(GVHolidays.DataKeys[e.RowIndex].Values[1].ToString());
     objHRPL.username = Session["username"].ToString();
     //objHRPL.sno = st;

     IFormatProvider provider1 = new System.Globalization.CultureInfo("en-CA", true);
     String dob = txtdat.Text.Trim().ToString();
     DateTime datedob = DateTime.Parse(dob, provider1, System.Globalization.DateTimeStyles.NoCurrentDateDefault);
     objHRPL.dob = datedob;

     objHRPL.remarks = txtreason.Text.ToString();
 
Share this answer
 
Comments
krranjeet9 15-Nov-13 2:03am    
this is not working
Siva Hyderabad 15-Nov-13 2:06am    
what u write the procedure for updation
?
Refer the Simple Example on the Code Project Article- Passing a datatable to a Stored Procedure in SQL Server 2008[^].
 
Share this answer
 
 
Share this answer
 
Comments
krranjeet9 15-Nov-13 2:03am    
by this we can pass one one argument not dataTable
ArunRajendra 15-Nov-13 2:10am    
You need to create Type of table. Follow the links within. Might be iam wrong as I am No expert on this.

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