Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Imports System.Data
Imports System.Data.Odbc
Partial Class _STUDENTTABLE
Inherits System.Web.UI.Page
Dim CON As OdbcConnection
Dim comm As OdbcCommand
Dim instance As OdbcDataAdapter
Dim a As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

End Sub

Protected Sub BTNINSERT_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BTNINSERT.Click
CON = New OdbcConnection("DSN=DBLOG;Driver=(Oracle in XE);UID=system;PWD=SYS;SERVER=localhost;")
CON.Open()
MsgBox("successfully opened")
comm = New OdbcCommand("INSERTSTUDENT", CON)
comm.CommandType = CommandType.StoredProcedure
comm.Parameters.AddWithValue("ID_", TXTID.Text)
comm.Parameters.AddWithValue("STUDENTNAME_", TXTNAME.Text)
comm.Parameters.AddWithValue("DEPARTMENT_", TXTDEPART.Text)
comm.Parameters.AddWithValue("YEAR_", TXTYEAR.Text)
comm = New OdbcCommand("{call INSERTSTUDENT(?, ?, ?, ?)}", CON)
a = comm.ExecuteNonQuery()
If a > 0 Then
MsgBox("success")
Else
MsgBox("fail")
End If
CON.Close()
MsgBox("successfully closed")
End Sub
Posted

1 solution

If you are querying an Oracle database using the System.Data.Odbc class, you can only use unnamed parameters (defined by "?"). In order to use named parameters, you’ll need to use the System.Data.OracleClient class instead (note you’ll need to add that reference manually to your project).

public DataTable queryDatabase_odbc () {
	OdbcConnection con = new OdbcConnection("Driver={Microsoft ODBC for Oracle};server=DBSERVER;uid=xxUserxx;pwd=xxPwdxx");
	con.Open();
	OdbcCommand ps = new OdbcCommand("alter session set current_schema = xxdbschemaxx", con);
	ps.Prepare();
	ps.ExecuteNonQuery();

	OdbcCommand ps2 = new OdbcCommand("select * from aTable where field = :AParam", con);
	ps2.Prepare();
	ps2.Parameters.Add("AParam",OdbcType.VarChar).Value="Some String Value";
	DataSet rs = new DataSet();
	OdbcDataAdapter da = new OdbcDataAdapter(ps2);
	da.Fill(rs);	// This will throw an exception
	return rs.Tables[0];
}

// The exact same code as above, just using the the OracleClient class
public DataTable queryDatabase_ora () {
	OracleConnection con = new OracleConnection("server=DBSERVER;uid=xxUserxx;pwd=xxPwdxx;");
	con.Open();
	OracleCommand ps = new OracleCommand("alter session set current_schema = xxdbschemaxx", con);
	ps.Prepare();
	ps.ExecuteNonQuery();

	OracleCommand ps2 = new OracleCommand("select * from aTable where field = :AParam", con);
	ps2.Prepare();
	ps2.Parameters.Add("AParam",OracleType.VarChar).Value="Some String Value";
	DataSet rs = new DataSet();
	OracleDataAdapter da = new OracleDataAdapter(ps2);
	da.Fill(rs);
	return rs.Tables[0];
}


For more details check this out : http://klo2k.wordpress.com/2009/03/21/asp-net-odbc-oracle-error-ora-01008-not-all-variables-bound-solved/[^]

I hope this will help to you.
 
Share this answer
 
v2

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