473,395 Members | 1,530 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Odbc parameter error

Hii all i have written following code for inserting records into
database but it gives me an error espected parameter @NewsTitle which
is not supplied.

OdbcConnection conn = new OdbcConnection();
protected System.Web.UI.WebControls.Button Button1;
OdbcCommand cmd =new OdbcCommand ();
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
OdbcParameter param =new OdbcParameter();

//class constructor
public TestAddRec()
{

conn.ConnectionString="DSN=vritti;uid=sa;pwd=sa";
cmd.Connection=conn;
conn.Open();
}

private void Button1_Click(object sender, System.EventArgs e)
{

cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="DS_SP_Insert_News";

param.OdbcType=OdbcType.VarChar;
param.Value = "@TextBox1.Text";
param.SourceColumn="@NewsTitle";

//param.ParameterName="Param1";
cmd.Parameters.Add(param);
OdbcParameter param1 =new OdbcParameter();
param1.OdbcType=OdbcType.VarChar;
param1.Value = "@TextBox2.Text";
param1.SourceColumn="@NewsDesc";
//param.ParameterName="Param2";
cmd.Parameters.Add(param1);

OdbcParameter param2 =new OdbcParameter();
param2.OdbcType=OdbcType.DateTime;
param2.Value = DateTime.Now.ToShortDateString();
param2.SourceColumn="@ModifiedDate";
//param.ParameterName="Param3";
cmd.Parameters.Add(param2);

OdbcParameter param3 =new OdbcParameter();
param3.OdbcType=OdbcType.Date;
param3.Value = DateTime.Now.ToShortDateString();
param3.SourceColumn="@AddedDate";
//param.ParameterName="Param4";
cmd.Parameters.Add(param3);

OdbcParameter param4 =new OdbcParameter();
param4.OdbcType=OdbcType.VarChar;
param4.Value = "Santosh";
param4.SourceColumn="@AddedBy";
//param.ParameterName="Param5";
cmd.Parameters.Add(param4);
cmd.ExecuteNonQuery();
Response.Write("<Script language=javascript>alert('Records are added
successfully');</script>");
}

Oct 5 '06 #1
2 2481
Looking at your parameters and how NewsTitle compares to your other parameters,
perhaps it's due to the fact that a new OdbcParameter hasn't been instanciated
for NewsTitle inside the button1_click. Have you tried moving it in there?

** OdbcParameter param = new OdbcParameter(); **
param.OdbcType=OdbcType.VarChar;
param.Value = "@TextBox1.Text";
param.SourceColumn="@NewsTitle";

//param.ParameterName="Param1";
cmd.Parameters.Add(param);

If not, is there a reason it's left outside?

-dl

--
David Longnecker
Web Developer
http://blog.tiredstudent.com
Hii all i have written following code for inserting records into
database but it gives me an error espected parameter @NewsTitle which
is not supplied.

OdbcConnection conn = new OdbcConnection();
protected System.Web.UI.WebControls.Button Button1;
OdbcCommand cmd =new OdbcCommand ();
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
OdbcParameter param =new OdbcParameter();
//class constructor
public TestAddRec()
{
conn.ConnectionString="DSN=vritti;uid=sa;pwd=sa";
cmd.Connection=conn;
conn.Open();
}
private void Button1_Click(object sender, System.EventArgs e)
{
cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="DS_SP_Insert_News";
param.OdbcType=OdbcType.VarChar;
param.Value = "@TextBox1.Text";
param.SourceColumn="@NewsTitle";
//param.ParameterName="Param1";
cmd.Parameters.Add(param);
OdbcParameter param1 =new OdbcParameter();
param1.OdbcType=OdbcType.VarChar;
param1.Value = "@TextBox2.Text";
param1.SourceColumn="@NewsDesc";
//param.ParameterName="Param2";
cmd.Parameters.Add(param1);
OdbcParameter param2 =new OdbcParameter();
param2.OdbcType=OdbcType.DateTime;
param2.Value = DateTime.Now.ToShortDateString();
param2.SourceColumn="@ModifiedDate";
//param.ParameterName="Param3";
cmd.Parameters.Add(param2);
OdbcParameter param3 =new OdbcParameter();
param3.OdbcType=OdbcType.Date;
param3.Value = DateTime.Now.ToShortDateString();
param3.SourceColumn="@AddedDate";
//param.ParameterName="Param4";
cmd.Parameters.Add(param3);
OdbcParameter param4 =new OdbcParameter();
param4.OdbcType=OdbcType.VarChar;
param4.Value = "Santosh";
param4.SourceColumn="@AddedBy";
//param.ParameterName="Param5";
cmd.Parameters.Add(param4);
cmd.ExecuteNonQuery();
Response.Write("<Script language=javascript>alert('Records are
added
successfully');</script>");
}

Oct 5 '06 #2
i have tired in other ways also but still it is giving same error . if
i am using sqlconnection, sqlcommand, sqlparameters then it works fine
but it gives an error when i am using Odbc.

--
David R. Longnecker wrote:
Looking at your parameters and how NewsTitle compares to your other parameters,
perhaps it's due to the fact that a new OdbcParameter hasn't been instanciated
for NewsTitle inside the button1_click. Have you tried moving it in there?

** OdbcParameter param = new OdbcParameter(); **
param.OdbcType=OdbcType.VarChar;
param.Value = "@TextBox1.Text";
param.SourceColumn="@NewsTitle";

//param.ParameterName="Param1";
cmd.Parameters.Add(param);

If not, is there a reason it's left outside?

-dl

--
David Longnecker
Web Developer
http://blog.tiredstudent.com
Hii all i have written following code for inserting records into
database but it gives me an error espected parameter @NewsTitle which
is not supplied.

OdbcConnection conn = new OdbcConnection();
protected System.Web.UI.WebControls.Button Button1;
OdbcCommand cmd =new OdbcCommand ();
protected System.Web.UI.WebControls.TextBox TextBox1;
protected System.Web.UI.WebControls.TextBox TextBox2;
OdbcParameter param =new OdbcParameter();
//class constructor
public TestAddRec()
{
conn.ConnectionString="DSN=vritti;uid=sa;pwd=sa";
cmd.Connection=conn;
conn.Open();
}
private void Button1_Click(object sender, System.EventArgs e)
{
cmd.CommandType=CommandType.StoredProcedure;
cmd.CommandText="DS_SP_Insert_News";
param.OdbcType=OdbcType.VarChar;
param.Value = "@TextBox1.Text";
param.SourceColumn="@NewsTitle";
//param.ParameterName="Param1";
cmd.Parameters.Add(param);
OdbcParameter param1 =new OdbcParameter();
param1.OdbcType=OdbcType.VarChar;
param1.Value = "@TextBox2.Text";
param1.SourceColumn="@NewsDesc";
//param.ParameterName="Param2";
cmd.Parameters.Add(param1);
OdbcParameter param2 =new OdbcParameter();
param2.OdbcType=OdbcType.DateTime;
param2.Value = DateTime.Now.ToShortDateString();
param2.SourceColumn="@ModifiedDate";
//param.ParameterName="Param3";
cmd.Parameters.Add(param2);
OdbcParameter param3 =new OdbcParameter();
param3.OdbcType=OdbcType.Date;
param3.Value = DateTime.Now.ToShortDateString();
param3.SourceColumn="@AddedDate";
//param.ParameterName="Param4";
cmd.Parameters.Add(param3);
OdbcParameter param4 =new OdbcParameter();
param4.OdbcType=OdbcType.VarChar;
param4.Value = "Santosh";
param4.SourceColumn="@AddedBy";
//param.ParameterName="Param5";
cmd.Parameters.Add(param4);
cmd.ExecuteNonQuery();
Response.Write("<Script language=javascript>alert('Records are
added
successfully');</script>");
}
Oct 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: GitarJake | last post by:
Hello all, I am trying to test an ODBC connection to an Oracle dbf using the ODBC Data Source Administrator. It's not working and I suspect I haven't configured Oracle correctly. Below is...
4
by: Roger Redford | last post by:
Dear Experts, I'm attempting to marry a system to an Oracle 817 datbase. Oracle is my specialty, the back end mainly, so I don't know much about java or javascript. The system uses javascript...
4
by: dcarson | last post by:
I've read about this error in several other discussions, but still can't seem to pinpoint the problem with my code. Everything seemed to be working fine for some time, but it now tends to bomb out...
5
by: Todd Huish | last post by:
I have noticed something disturbing when retrieving datasets over a relatively slow line (multiple T1). I am looking at about 25 seconds to retrieve 500 rows via a php-odbc link. This same select...
2
by: Bibi | last post by:
Hi, i have a SqlWindows Program which made a connection to a MS Access Database about ODBC. I can get all datas with a select about one table. But when i made a select with more than one table,...
1
by: TheKval | last post by:
I'm trying to pull records on a Macola table linked to Access. If enter a value in the criteria field of the query form, the quer executes okay. If I change the criteria to a parameter, ala, , I...
0
by: Marco Martin | last post by:
Hi group, I have an app that accesses an Access DB. We are using odbc because this app will probably be using other databases as well dependiing on the clients needs. Consider the following;...
3
by: juststarter | last post by:
Hello all, I am executing a stored procedure (on an SQL Server) using ODBC but i can't get the output parameter's value on the client. The stored proc has 3 parameters ,2 of them are input and 1...
1
by: chloe.crowder | last post by:
Hi We're trying to use call a stored procedure to update information in a remote Ingres database. We've linked the server, and can read information using SELECT * FROM OPENQUERY (..........),...
4
by: Szymon Dembek | last post by:
Hi Recently I did some DB2 and ODBC coding in Visual FoxPro. I bumped on a problem I cannot resolve. When I issue a delete statement that deletes no rows (no rows qualify for the WHERE...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.