Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
public static void AddNew(string stu_name, string address, string Phone, datetime date)
        {
       String sql = "Select I_Student_ID.NEXTVAL from dual;
       Int newStudent_ID = 0;
  OracleDatabase db = (OracleDatabase)DatabaseFactory.CreateDatabase("PHTS");
    using (System.Data.Common.DbCommand cmd = db.GetSqlStringCommand(sql))
            {
                newStudent_ID = Convert.ToInt32(db.ExecuteScalar(cmd));
            }
     
        OracleDatabase db = (OracleDatabase)DatabaseFactory.CreateDatabase("PHTS");
 
 using (System.Data.Common.DbCommand cmd = db.GetStoredProcCommand("AddNewStudent"))
            {
                db.AddInParameter(cmd, "I_Student_ID",DbType.Int32,newStudent_ID);
                db.AddInParameter(cmd, "I_STU_Name", DbType.String,stu_name);
                db.AddInParameter(cmd, "I_Address", DbType.String,address);
                db.AddInParameter(cmd, "I_Phone", DbType.String,Phone);
                db.AddInParameter(cmd, "I_Date", DbType.date,date);
 
               db.ExecuteNonQuery(cmd);
 
            }
 
        }
    }


Stored Procedure in Oracle
Create or replace PRPCEDURE AddNewStudent (
I_STU_ID    Number,    
I_STU_Name  Varchar2,
I_Address  Varchar2,
I_Phone  Varchar2,
I_Date   date,
)
As
Begin
Insert into I_Student
(
Student_ID, STU_Name, Address, Phone, Date
)
Values
(
I_Student_ID, I_STU_Name, I_Address, I_phone, I_Date
);

The stored Procedure is working fine in oracle. I am getting error mismatch datatype for the date. How can I bind the date datatype in my parameter. 


User interface

C#
private void savebutton_Click(object sender, EventArgs e)
        {
            string student = this.STU_NameTextBox.Text;
            string address = this.addressTextBox.Text;
            string phone = this.phoneTextBox.Text;
            string date = DateTime.Parse(this.DatetextBox.Text).ToString("MM/dd/yyyy");
         
            AddNew(STU_Name, address, Phone,date);


Now I am getting " Error Cannot implicitly convert type 'string' to 'System.DateTime' "

Thanks
Posted
Updated 29-Jul-11 14:39pm
v3

Use db.AddInParameter(cmd, "I_Date", DbType.Date,date);
instead of db.AddInParameter(cmd, "I_Date", DbType.datetime,date);

this should solve your problem, besides this there is nothing wrong in the code.


With kudos,

Pradeep
 
Share this answer
 
C#
string date = DateTime.Parse(this.DatetextBox.Text).ToString("MM/dd/yyyy");
            AddNew(STU_Name, address, Phone,date);


your input parameter for AddNew(string ,string ,string, datetime)
but you are trying to send string value to datetime parameter.
 
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