473,746 Members | 2,672 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

update the database using dataadpater in asp.net

35 New Member

I have written this code on button_click event.
but it shows "Object reference not set to an instance of an object" error.
can u help to solve this error.

String conn= "data source= VTECHS; database= bc;uid=greymoun t;password= manish2809";
String str= "select * from details";
SqlDataAdapter da= new SqlDataAdapter( str,conn);
SqlCommandBuild er commb=new SqlCommandBuild er(da);
DataSet ds =new DataSet();
DataTable dt=new DataTable();
dataRow rownew= ds.Tables["details"].NewRow();
rownew["name"]=txtLcode.Text ;
ds.Tables["details"].Rows.Add(rowne w);
Dec 14 '06 #1
10 4251
692 Recognized Expert Contributor
Have u opened the connection?
because SqlDataAdapter da= new SqlDataAdapter( str,conn);
Here con is your connectionstrin g .So yuo might be getting error there

Dec 14 '06 #2
35 New Member
Thanks for reply........
but i have opened the connection in the code.

I have written like tht but it is still not working.

SqlConnection conn= new SqlConnection ("data source= VTECHS; database= abc;uid=greymou nt;password= manish2809");

SqlDataAdapter da= new SqlDataAdapter( new SqlCommand("sel ect * from details",conn)) ;

Please help me to solve this query.
Dec 14 '06 #3
759 Recognized Expert Contributor
Why did u use the command builder there ?

Remove the command builder.

Also, when u create a Datase, it has a Data Table.

U can access it directly by ds.Tables[0]

Try to reduce the code and finish it.

Dec 14 '06 #4
25 New Member
check if the database already exists for which your trying to access from code.
also debug and find out where exactly its breaking...
Dec 14 '06 #5
35 New Member
thanks for reply.

actually I want to insert the new record into the table.
Dec 14 '06 #6
35 New Member
when I debug, error is showing in this line

dataRow rownew= ds.Tables["details"].NewRow();
Dec 14 '06 #7
25 New Member
dataRow rownew= ds.Tables["details"].NewRow();[/quote]

make the above line

DataRow rownew= ds.Tables["details"].NewRow();[/quote]
the datarow should b in caps..
and plz check u have this at the top
using System.Data;
using System.Data.Sql Client;
Dec 14 '06 #8
35 New Member

my problem is solved.

now I have used ds.Tables[0].
but command builder is necessary becoz I want to insert new record into table
& it provides many other useful commands to dataadapter such as insert command which is useful for adding the new record into database.

Why did u use the command builder there ?

Remove the command builder.

Also, when u create a Datase, it has a Data Table.

U can access it directly by ds.Tables[0]

Try to reduce the code and finish it.

Dec 15 '06 #9
25 New Member
DataTable dt =new DataTable();


that was the gud soln to the probs i thought u could have done this..
thats taking new row from the datatable instead of ds..
Dec 15 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Niyazi | last post by:
Hi, I have not understand the problem. Before all the coding with few application everything worked perfectly. Now I am developing Cheque Writing application and when the cheque is clear the user have to open a form and entera date so we know in report that the desiered check has been cleared. It takes me while to wrtie. But when I try to update the datagrid changes via dataset to MS Access 2003 I get an error that simply says...
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums must be UPDATED, if not, they must be INSERTED. Logically then, I would like to SELECT * FROM <TABLE> WHERE ....<Values entered here>, and then IF FOUND UPDATE <TABLE> SET .... <Values entered here> ELSE INSERT INTO <TABLE> VALUES <Values...
by: Mojtaba Faridzad | last post by:
Hi, Please check these lines: DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet, "mytable"); DataRow row; row = dataSet.Tables.Rows; row.BeginEdit(); row = "555";
by: Paulb1us | last post by:
I want to update records from a csv file. I do this in a button click: //Create Adapters da = new OdbcDataAdapter("Select * FROM test.csv", conn); //Fill a data table da.Fill(dt);
by: Vijay Balki | last post by:
I am fetching data in DataSet - myDataSet, from a remote database using a Web Service in my VB.NET client..Once I fetch it I store the data in XML file (myXMLFile) using the WriteXML method of the myDataSet. The connection to the Web Service is closed at this point. I update this XML file in my application, and when I am ready to send the data back, I load the XML file back to a DataSet - mySendDataSet, using ReadXML method. Now I...
by: Zorpiedoman | last post by:
I keep getting a concurrency exception the second time I make a change and attempt to update a dataadapter. It appears this is by design, so there must be something I can do to avoid it. Example: I have a dataadapter that contains one table with one row. I change the value of the 'FisrtName' column in that row from Jack to John. I call ..update on the dataadapter it goes through fine. Now I change that same column in that same row...
by: Miro | last post by:
I will ask the question first then fumble thru trying to explain myself so i dont waste too much of your time. Question / Statement - Every mdb table needs a PrimaryKey ( or maybe an index - i havnt tested the index yet ) so you can use an .UPDATE( dataTable ) on the data adapter. Otherwise you will get an exception error. Is this statement true? ---- Now me fumbling thru
by: chandu | last post by:
Hi Guys, i am beginer in the worls of Asp.net and C#.net I have one problem that I have stored my changes of data into dataset using disconnected dataset and after completion of all changes i want to update that change to the database using stored procedure. But i am not getting How to do it,
by: Michel Esber | last post by:
Hi all, DB2 V8 LUW FP 15 There is a table T (ID varchar (24), ABC timestamp). ID is PK. Our application needs to frequently update T with a new value for ABC. update T set ABC=? where ID = ?
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.