Odbc parameter error

S

Santosh

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>");
}
 
D

David R. Longnecker

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
 
S

Santosh

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.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top