Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,
In my application i want to insert values to mysql table using c#. For that i have to move to next record of that table. How to move to record?

Thanks in advance.
Posted
Comments
Nilesh Patil Kolhapur 22-Feb-12 2:33am    
do u want next primary key Id or what? Explain More
psgviscom 22-Feb-12 2:43am    
In my application i inserted a row in mysql table. I want to insert another row also. So for that i want to move to next record (or row).

1 solution

Dear in order to insert a new record you have to create a new id by fetching the max(ID) from the mysql table and adding one increment to it like for example:-
DAL.ExecuteNonQuery("insert into [table] (id,name,...) values (getMaxID(),'Vishnu',..))");

where DAL is the data access layer for SQL Server & .net and getMaxID() is the method which will return the max id for insertion of new record i.e.,
return int ID = DAL.ExecuteScalar("select max(id) from [table]");


I hope this example will help you out to understand how to insert new record.
 
Share this answer
 
Comments
psgviscom 22-Feb-12 2:45am    
I used auto_increment for my id. So it automatically increased when we insert a row. In my application i inserted a row in mysql table. I want to insert another row also. So for that i want to move to next record (or row).
Varun Sareen 22-Feb-12 4:15am    
try to check that the record which you are inserting is not the same record on the basis of distinct fields in your table for a particular row/entry and then execute the insert query.

As you have the ID as auto increment then the insertion of new record will be done at new new row with different ID. I hope you get this time.
psgviscom 22-Feb-12 4:24am    
Thank you for your replies. I solved my problem. There was some problem in connection. I solved it.
Varun Sareen 22-Feb-12 21:31pm    
good

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