Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i am new to development and want to know about the insertion deletion and updating of record from a FORM to database ,
Posted
Updated 19-Nov-19 21:22pm
Comments
Sergey Alexandrovich Kryukov 14-Aug-11 2:32am    
A Form is irrelevant to database; it least it should be.
--SA

 
Share this answer
 
It might be helpful,

Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]

and further reading,

ADO.NET[^]

:)
 
Share this answer
 
You can get idea about insertion and Upadtion
For insertion
C#
public static bool Insert_File(string FileNo, string CUSTOMER_NAME, string ProjectName, string STATUS,string date,string ins)
    {
        try
        {
            string stinsert = "Insert into File (FileNo,CUSTOMER_NAME,ProjectName,STATUS,IDate,InsertedBy) values (@FileNo,@CUSTOMER_NAME,@ProjectName,@STATUS,@date,@ins)";
            //string stinsert1 = "Insert into FileCord (FileNo,CUSTOMER_NAME,ProjectName,STATUS,IDate) values (@FileNo,@CUSTOMER_NAME,@ProjectName,@STATUS,@date)";
            
            OleDbCommand cmdinsert = new OleDbCommand(stinsert, GetConnection());
           
            cmdinsert.Parameters.AddWithValue("FileNo", FileNo);
            cmdinsert.Parameters.AddWithValue("CUSTOMER_NAME", CUSTOMER_NAME);
            cmdinsert.Parameters.AddWithValue("ProjectName", ProjectName);
            cmdinsert.Parameters.AddWithValue("STATUS", STATUS);
            cmdinsert.Parameters.AddWithValue("date",date);
            cmdinsert.Parameters.AddWithValue("ins",ins);
            cmdinsert.ExecuteNonQuery();
            cmdinsert.Connection.Close();
            return true;
           
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.ToString());
            return false;
        }
    }

For Update
public static bool Update_Received(string FileNo, string ReqControlNo, string ReceiveDate, string Remarks, string received)
    {
        try
        {
            string s1 = "Update Issue set ReceivedDate='" + ReceiveDate + "',ReceivedRemarks= '" + Remarks + "',ReceiveTime='" + received + "' where FileNo='" + FileNo + "' AND ReqControlNo='" + ReqControlNo + "'";
            OleDbCommand cmd1 = new OleDbCommand(s1, GetConnection());
            cmd1.ExecuteNonQuery();
            cmd1.Connection.Close();
            string stts = "Available";
            string st3 = "Update File set STATUS='" + stts + "' where FileNo='" + FileNo + "' ";
            OleDbCommand cmd11 = new OleDbCommand(st3, GetConnection());
            cmd11.ExecuteNonQuery();
            cmd11.Connection.Close();

            return true;

        }
        catch (Exception ex)
        {

            System.Windows.Forms.MessageBox.Show(ex.ToString());
            return false;
        }
 
Share this answer
 
Comments
arslan3488 13-Aug-11 5:27am    
but when we use sql 2008 then what will be the way do this all stuff
uspatel 17-Aug-11 5:18am    
you can use Sql in place of OleDb for sql server

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