Forms Data Controls :: Insert Data From Gridview To Dataset?
Jan 19, 2010
I `m working in aprojct taht read Excel files then insert tables from excel files to dataset then display these tables into Gridview , All these ok with me
The problem here is
How to insert updated data from gridview to dataset again?
I search for it more & more but i didn`t find any thing to do it
i have 103 column in database 1 column is id, 1 is user ,1 datetime, 100 button on webpage 1 textbox to input value , button1 clicked then value in textbox will insert into database with user:=user.identity.nam datetime=datetime.now colum4 will get value from textbox......button2 for colum2 and buton100 for column100, if i use dataset i need 100 datataset, some other way to solve it ??
Codebehind: creating dataset, getting data from sql with adaptor and filling into dataset object, then setting detailsview's datasource. I add 2 button to above template to able to edit data at asp page, and added event handlers:buttons:
[Code]....
My question is, what to do inside the detailsview update event function to able to edit and update data. My method can be wrong too.
I have the following code: using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using Oracle.DataAccess.Client; // ODP.NET Oracle managed provider using Oracle.DataAccess.Types;
namespace MyTestApp { public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { OracleConnection conn = new OracleConnection("User Id=UID; Password=PWD; Data Source=XE; Pooling=false"); try { conn.Open(); } catch ( OracleException oe ){ Console.WriteLine("ERROR : " + oe.Message); } if ( !Page.IsPostBack ) { if (conn.State == ConnectionState.Open) { // get data GetMoleculesToShow(conn); } } // clean up connection conn.Dispose(); } static void GetMoleculesToShow( OracleConnection conn ){ String division; String rxotc; String molecule_name; String prodnum; String proddesc; String molecule_class; String nonactive; // create command object and set attributes OracleCommand cmd = new OracleCommand("schema.package.procedure", conn); cmd.CommandType = CommandType.StoredProcedure; //Bind values cmd.Parameters.Add("mol_to_show_cur", OracleDbType.RefCursor); cmd.Parameters[0].Direction = ParameterDirection.Output; try { // Execute command, have parameters populated cmd.ExecuteNonQuery(); // Create OracleDataAdapter, data provider object to populate dataset OracleDataAdapter da = new OracleDataAdapter(cmd); //Populate dataset with "molrefcur" DataSet ds = new DataSet(); da.Fill(ds, "mol_to_show_cur", (OracleRefCursor)(cmd.Parameters["mol_to_show_cur"].Value)); //Verify dataset is begin populated //DataTable dt = ds.Tables[0]; //foreach ( DataRow dr in ds.Tables[0].Rows ) //{ // division = dr["division"].ToString(); // rxotc = dr["rxotc"].ToString(); // molecule_name = dr["molecule_name"].ToString(); // prodnum = dr["prodnum"].ToString(); // proddesc = dr["proddesc"].ToString(); // molecule_class = dr["molecule_class"].ToString(); // nonactive = dr["nonactive"].ToString(); //} if (ds.Tables[0].Rows.Count != 0) { // display dataset values GridView gvMolecules = new GridView(); gvMolecules.DataSource = ds.Tables["mol_to_show_cur"].Rows; gvMolecules.DataBind(); } } catch (OracleException oe) { Console.WriteLine("ERROR : " + oe.Message); } finally { cmd.Dispose(); } } } }
The dataset is being populated, however when the page renders, the data nor the gridview are visible. I have tried using both IE and Firefox, binding / not binding the columns, AutoGenerateColumns Y / N with no success. As I am new to all of this ( VS2008, ASP.NET, C# ) I can't help but to think I am overlooking something basic.
I am using the following : - VS 2008 - MS Vista SP2 - Oracle XE ( local )
I have a Gridview and two link button in that GridView , one link button click is to add edit row ( Edit ), one link button click is to select row ( Select ). I have a dropdownlist inside row which selected when i click link button Select in the gridview edit template, as of my business logic i need to show the dropdownlist only when the user clicks Edit button and when the user clicks Select button . That mean when the user clicks Select button then they clicks Edit button on the gridvview i should allow him to edit the dropdownlist (showing the value to the user through a label).
ASPX CODE
[Code].... C#
When I click Select link button , then I click Edit link button . They have errors : Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index" I don't know what error?. How to fix it
I have grid view in ASP.Net 3.5. I need to add multiple blank rows in a gridview and then have to save them in database. How can I do that in most simplest way?
I want to display child rows in the datagrid after the + sign is selected (like grouping & outlining in excel). This is automatic in infragistic grids but when i did in asp (no more infragistics) it doesnt work. here is my code (very simple stuff)
How to display empty GridView to insert new record if no data retreived for some record on the result from data table?Actually i am trying to give a user an option to add recrod from Gridview. On result of some query it is perfectly displaying data and a footer row with the insertion textbox but when there is no data in the gridview it is not displaying. It should display with footer having insert textbox.
If the gridview binds to empty dataset, I need to still show a gridview so that users can ADD more using the textfields in the bottom of the footer template. Since the gridview is empty it won't bind not allowing rendering of the <footer template> I guess I should create a empty dataset if the gridview is empty. How do I check for this and can this be done in GridviewRowEventArgs
I have a set of dataset with different column retrieved from DB. I need to present the datasets in one GridView (or other ListView etc...) without specifying the column_header. It should present automaticly since the GridView is bind to the DataSet.
In additional, I want this GridView to handle multiple rows edit and update the dataset, idealy, show data in textboxs in initially.How could I set the GridView to edit_model without hardcode column_header and textboxs in 'itemtemplate' or filed.
How could I achieve the bulk edit and update, so that I can assign 'mydataview1.table' to the dataset.
i'm currently doing a shopping website. The customer will have to selected the item they want to buy and it will appear in the detail view when they click add in the grid view. I need the info inside the detail view to be insert into a database call Orderlist.
i've try using INSERT INTO OrderList (ProductName, Price,) VALUES (@ProductName, @Price) but it don't seems to work.
Was it because i can't insert it like this as it is detailview? This method can work if is Textbox instead of detailview.
i have a gridview of 8 columns.I need to extract the data row by row from the the first(Message) and the last(phone_no) column and to be inserted into my sql table named massMessage.I have the codes here. Apparently im able to only extract the phone_no. My message wasnt inserted.
protected void btnSave_Click(object sender, EventArgs e) { foreach (GridViewRow gvr in GridView2.Rows) //loop through GridView
I have a gridview that I load with data from an Excel spreadsheet when the user pushes a button. I then want another button that would insert all the data from the gridview into a sql table when the button is pressed. I'm using vb.
I have a tricky situation that I just cannot seem to figure out. I'm using ASP.NET 4.0. I have two databases (let's call them Northwind and MyDatabase for simplicity). I cannot modify the data in Northwind, but once I save a copy to MyDatabase, I can change it.
I have a GridView that shows all the tests associated with a patient. I first populate the GridView, retrieving all the tests in Northwind.Test that are associated to a PatientID. On a button click event, I need to: Create a new Patient record in MyDatabase.Patient (I've got this part done already).Use that newly created PatientID and INSERT all of the rows from the GridView intoMyDatabase.Test.
I have the PatientID available, I just don't know how to retrieve the data from the GridView.(Ideally) I would like to then be able to load that patient record in the future from MyDatabase and be able to UPDATE the tests in the GridView to MyDatabase.Test. I can load the tests into the GridView no problem. But I have no idea how I would save that data to a different datasource. Should I even be using a GridView, or something else?
I am trying to return a dataset. I must be doing something wrong. The returned dataset in this sample code indicates there is a datatable, Users, but there are no datarows. What am I doing wrong? This example is only using the rows.count, but of course I really need to use the whole datatable as the datasource for a gridview.
[Code]....
Public Function getmyds() As DataSet Dim dsUser1 As DataSet = New DataSet() Dim tbUser1 As DataTable = dsUser1.Tables.Add("Users") tbUser1.Columns.Add("UserName") tbUser1.Columns.Add("Days Remaining") tbUser1.Columns.Add("UserAccountControl") Dim rwDefaultUser1 As DataRow = tbUser1.NewRow() rwDefaultUser1("UserName") = "John Smith" rwDefaultUser1("Days remaining") = 100 rwDefaultUser1("userAccountControl") = "Enabled" Return dsUser1 End Function
I need to know how to display a single row(or particular row)from dataset and display into gridview... i tried by using some codes, like the following, If strCourseLevelId <> "" Then Dim ds2 As DataSet Dim currentbundlenid As Int16 Dim prevbundleid As Int16 = "0" Dim bundlenos As Int16 = "0" Dim bundlecontent As Bundledata = New Bundledata ds2 = bundlecontent.GetBundleData(strCourseLevelId) If ds2.Tables.Count = 1 Then If ds2.Tables(0).Rows.Count > 0 Then With ds2.Tables(0) Dim strCnt As Int16 For strCnt = 0 To .Rows.Count - 1 With .Rows(strCnt) currentbundlenid = .Item("Bundleid") If currentbundlenid <> prevbundleid Then bundlenos = bundlenos + 1 End If If bundlenos = "1" Then GridView1.DataSource = ds2 GridView1.DataBind() ElseIf bundlenos = "2" Then GridView2.DataSource = ds2 GridView2.DataBind() ElseIf bundlenos = "3" Then GridView3.DataSource = ds2 GridView3.DataBind() End If prevbundleid = .Item("Bundleid") 'next write the main page content End With Next End With End If End If.