Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public static void AddNewInventory(string stu_name, string address, string Phone, string date)
        {
            string sql = "BEGIN Insert into I_Student " +
                "Student_ID, STU_Name, Address, Phone, DATE " +
                   "Values(I_Student_ID.NextVAL, :STU_Name, :Address, :Phone,to_date(:DATE, 'MM/DD/YYYY HH24:MI:SS')); END; ";

            Console.WriteLine("Insert SQL = " + sql.ToString());
            OracleDatabase db = (OracleDatabase)DatabaseFactory.CreateDatabase("PHTS");

            using (System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql))
            {


                db.AddInParameter(cmd, "STU_Name", DbType.String,stu_name);
                db.AddInParameter(cmd, "Address", DbType.String,address);
                db.AddInParameter(cmd, "Phone", DbType.String,Phone);
                db.AddInParameter(cmd, "DATE", DbType.String,date);

               db.ExecuteNonQuery(cmd);

            }

        }
    }



How can I bind the auto generated number to a textbox
Posted
Updated 28-Jul-11 14:07pm
v2

1 solution

Assuming you mean Auto Generated ID, here are some steps you might want to take.

1. Add an output parameter using AddOutParameter[^]
2. Modify the query and assign the auto generated ID to the parameter you have created.
3. After db.ExecuteNonQuery(cmd), get the value of the output parameter by using GetParameterValue[^] and then assign it to your textbox.
 
Share this answer
 

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