By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 664 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

adding data from textbox to oracle table

varunmcaju
P: 4
hi everyone, this is my first post and i hope that i would find a solution to my problem. I have a textbox called "txtPurpose" in a C# Windows Application in Visual Studio, and i want that the text entered by the user in the textbox should be added to the "PURPOSE" field in a table "TABLE2_HDB1" in Oracle database "HDB1" on clicking a "submit" button. I want the coding to be in C#. plz help
Jul 7 '08 #1
Share this Question
Share on Google+
5 Replies


debasisdas
Expert 5K+
P: 8,127
kindly post what you have tried so far and in which part of the code you are struck.

Please find related articles here .
Jul 7 '08 #2

varunmcaju
P: 4
Hi Debasisdas,thanks for replying..i want that on clicking a "submit" button the data entered by the user in the textbox "txtPurpose" should be added to the PURPOSE field of Oracle table TABLE2_HDB1 of the Oracle database HDB1. i am using the following code:
i am passing the textbox value to function Insert like:
Insert(txtPurpose.Text);


private bool Insert(string field)
{
bool success = false;

string constr = "Provider=MSADORA;Data Source=HDb1;User Id=SYSTEM;Password=******";
OleDbConnection con = new OleDbConnection(constr);
try
{
OleDbCommand sc = new OleDbCommand("insert into TABLE2_HDB2 (PURPOSE) values '" + field + "'", con);
sc.CommandType = CommandType.Text;
if (sc.ExecuteNonQuery() > 0) success = true;
}
catch (OleDbException sq)
{
MessageBox.Show("Error : " + sq.Message);
}
finally
{
if (con.State != ConnectionState.Closed) { con.Close(); }
con.Dispose();
}
return success;
}
here,i am getting the error that "sc.ExecuteNonQuery() > 0 requires an open and available connection,the connection state is currently closed". But i've checked the connection state and it is open. Then i added the statement :- con.Open(); after OleDbConnection con = new OleDbConnection(constr);
Now i'm getting the error : "the provider MSADORA is not registered on the local machine" . what do i do now? is the code correct? how do i register MSADORA on the local machine?
Jul 9 '08 #3

debasisdas
Expert 5K+
P: 8,127
is oracle installed on your pc ?

Try to use other available drivers to connect to oracle like microsoft oledb provider for oracle.
Jul 9 '08 #4

varunmcaju
P: 4
hi debasisdas, now i am trying a different code for the submit button. the coding is as follows :-

private void button1_Click(object sender, EventArgs e)
{
string OracleStmt;
string ConString;
OleDbConnection cn = null;
OleDbCommand cmd = null;
try
{
OracleStmt = "insert into TABLE2_HDB1(PURPOSE) values(@PURPOSE)";
ConString = " Provider=MSDAORA;Data Source=HDb1;User Id=SYSTEM

;Password=*****;";
cn = new OleDbConnection(ConString);
cmd = new OleDbCommand(OracleStmt, cn);

cmd.Parameters.Add(new OleDbParameter("@PURPOSE", OleDbType.VarChar , 20));
cmd.Parameters["@PURPOSE"].Value = txtPurpose.Text;
cn.Open();

cmd.ExecuteNonQuery();
textBox8 .Text = "record inserted successfully";
}
catch (Exception ex)
{
textBox8 .Text = ex.Message;
}
finally
{
cn.Close();
}
}

on executing this code i am getting the error message:-

ORA-00936:missing expression.

what's causing this error?
Jul 15 '08 #5

debasisdas
Expert 5K+
P: 8,127
Try using this

OracleStmt = "insert into TABLE2_HDB1(PURPOSE) values(" & @PURPOSE & ")";
Jul 15 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.