Insert into table through parameter

kumarop

New member
Joined
Sep 19, 2005
Messages
1
Programming Experience
Beginner
Dear All,
Database - orcale 8i
language - c#


i want to learn the use of parameter. And trying to insert into test table through parameter. I have two textboxes and i want on button click value should be inserted into database.

Tabale structure of "TEST"

(ONE varchar2(100)
TWO varchar2(100) )
i have checked connection is correct ,as i am able to retrive data from same table and connection.

Error-
One or more errors occurred during processing of command. ORA-0093missing 6: expression



VB.NET:
[color=#0000ff]using[/color][b] System;

[/b][color=#0000ff]using[/color][b] System.Collections;

[/b][color=#0000ff]using[/color][b] System.ComponentModel;

[/b][color=#0000ff]using[/color][b] System.Data;

[/b][color=#0000ff]using[/color][b] System.Drawing;

[/b][color=#0000ff]using[/color][b] System.Web;

[/b][color=#0000ff]using[/color][b] System.Web.SessionState;

[/b][color=#0000ff]using[/color][b] System.Web.UI;

[/b][color=#0000ff]using[/color][b] System.Web.UI.WebControls;

[/b][color=#0000ff]using[/color][b] System.Web.UI.HtmlControls;

[/b][color=#0000ff]using[/color][b] System.Data.OleDb;

[/b][color=#0000ff]namespace[/color][b] op1

{

[/b][color=#808080]///[/color][color=#008000] [/color][color=#808080]<summary>

[/color][b][/b][color=#808080]///[/color][color=#008000] Summary description for commandexecute.

[/color][b][/b][color=#808080]///[/color][color=#008000] [/color][color=#808080]</summary>

[/color][b][/b][color=#0000ff]public[/color][color=#0000ff]class[/color][b] commandexecute : System.Web.UI.Page

{

[/b][color=#0000ff]protected[/color][b] System.Web.UI.WebControls.Label Label1;

[/b][color=#0000ff]protected[/color][b] System.Web.UI.WebControls.Label Label2;

[/b][color=#0000ff]protected[/color][b] System.Web.UI.WebControls.TextBox TextBox1;

[/b][color=#0000ff]protected[/color][b] System.Web.UI.WebControls.TextBox TextBox2;

[/b][color=#0000ff]protected[/color][b] System.Web.UI.WebControls.DataGrid DataGrid1;

[/b][color=#0000ff]protected[/color][b] System.Web.UI.WebControls.Button Button1;



[/b][color=#0000ff]private[/color][color=#0000ff]void[/color][b] Page_Load([/b][color=#0000ff]object[/color][b] sender, System.EventArgs e)

{

[/b][color=#008000]// Put user code to initialize the page here

[/color][b]}

[/b][color=#0000ff]#region[/color][b] Web Form Designer generated code

[/b][color=#0000ff]override[/color][color=#0000ff]protected[/color][color=#0000ff]void[/color][b] OnInit(EventArgs e)

{

[/b][color=#008000]//

[/color][b][/b][color=#008000]// CODEGEN: This call is required by the ASP.NET Web Form Designer.

[/color][b][/b][color=#008000]//

[/color][b]InitializeComponent();

[/b][color=#0000ff]base[/color].OnInit(e);

[b]}



[/b][color=#808080]///[/color][color=#008000] [/color][color=#808080]<summary>

[/color][b][/b][color=#808080]///[/color][color=#008000] Required method for Designer support - do not modify

[/color][b][/b][color=#808080]///[/color][color=#008000] the contents of this method with the code editor.

[/color][b][/b][color=#808080]///[/color][color=#008000] [/color][color=#808080]</summary>

[/color][b][/b][color=#0000ff]private[/color][color=#0000ff]void[/color][b] InitializeComponent()

{ 

[/b][color=#0000ff]this[/color].Button1.Click += [color=#0000ff]new[/color][b] System.EventHandler([/b][color=#0000ff]this[/color].Button1_Click);

[b][/b][color=#0000ff]this[/color].Load += [color=#0000ff]new[/color][b] System.EventHandler([/b][color=#0000ff]this[/color].Page_Load);

[b]}

[/b][color=#0000ff]#endregion

[/color][b][/b][color=#0000ff]private[/color][color=#0000ff]void[/color][b] Button1_Click([/b][color=#0000ff]object[/color][b] sender, System.EventArgs e)

{

[/b][color=#0000ff]string[/color][b] connectionstring = "Provider=MSDAORA.1;User ID=scott;Data Source=test;Password=tiger2";

OleDbConnection conn = [/b][color=#0000ff]new[/color][b] OleDbConnection(connectionstring);

conn.Open();



[/b][color=#0000ff]string[/color][b] querystring = "INSERT into TEST(one,two) VALUES(@ONE,@TWO)";

OleDbCommand command = [/b][color=#0000ff]new[/color][b] OleDbCommand(querystring,conn);







OleDbParameter fnparam = [/b][color=#0000ff]new[/color][b] OleDbParameter("@ONE",OleDbType.VarChar,100);

command.Parameters.Add(fnparam);

fnparam.Value = TextBox1.Text; 

[/b][b]

OleDbParameter inparam = [/b][color=#0000ff]new[/color][b] OleDbParameter("@TWO",OleDbType.VarChar,100);

command.Parameters.Add(inparam);

inparam.Value = TextBox2.Text;

[/b][color=#0000ff]try

[/color][b]{

command.ExecuteNonQuery();

}

[/b][color=#0000ff]catch[/color][b](Exception exp)

{

Response.Write (exp.Message);

}

[/b][b]conn.Close();

}

}

}

[/b]

I know it can be done differently but i am doing it for concept. Can u refer some reading material on it( can it be found on MSDN)

Regards,
 
Back
Top