473,411 Members | 2,059 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

update the database using dataadpater in asp.net

35
hello,

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=greymount;password= manish2809";
String str= "select * from details";
SqlDataAdapter da= new SqlDataAdapter(str,conn);
SqlCommandBuilder commb=new SqlCommandBuilder(da);
DataSet ds =new DataSet();
da.Fill(ds);
DataTable dt=new DataTable();
dt=ds.Tables["details"];
dataRow rownew= ds.Tables["details"].NewRow();
rownew["name"]=txtLcode.Text ;
ds.Tables["details"].Rows.Add(rownew);
da.Update(ds);
Dec 14 '06 #1
10 4229
shweta123
692 Expert 512MB
Have u opened the connection?
because SqlDataAdapter da= new SqlDataAdapter(str,conn);
Here con is your connectionstring .So yuo might be getting error there

Shweta
Dec 14 '06 #2
muskan
35
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=greymount;password= manish2809");
conn.Open();

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

Please help me to solve this query.
Dec 14 '06 #3
radcaesar
759 Expert 512MB
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
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
muskan
35
thanks for reply.

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

dataRow rownew= ds.Tables["details"].NewRow();
Dec 14 '06 #7
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.SqlClient;
Dec 14 '06 #8
muskan
35
thanks......

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
DataTable dt =new DataTable();
dt=ds.Tables["details"];

//ds.Tables["details"].NewRow();
dt.NewRow();

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
hello,

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=greymount;password= manish2809";
String str= "select * from details";
SqlDataAdapter da= new SqlDataAdapter(str,conn);
SqlCommandBuilder commb=new SqlCommandBuilder(da);
DataSet ds =new DataSet();
da.Fill(ds);
DataTable dt=new DataTable();
dt=ds.Tables["details"];
dataRow rownew= ds.Tables["details"].NewRow();
rownew["name"]=txtLcode.Text ;
ds.Tables["details"].Rows.Add(rownew);
da.Update(ds);


Its give me ==>a syntax error in insert into statement.
please solve my problem
Feb 15 '07 #11

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

Similar topics

2
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...
16
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...
2
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";
3
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);
0
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...
8
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. ...
2
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...
2
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...
3
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
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...
0
agi2029
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.