problem with insert query

condor

Member
Joined
Mar 11, 2006
Messages
20
Programming Experience
1-3
Hello ..

I made a program that has insert , update and delete ... am using VS.NET 2003 and sql 2000 ... the following code that i use it for insert ...
VB.NET:
If (txtEqCode.Text <> "" AndAlso txtVichNo.Text <> "") Then
With danew.InsertCommand
.CommandText = "INSERT INTO main (Code, Plateno, Serialno,Model,ki,Description,Specification,Note) VALUES (@Code, @Plateno, @Model,@ki,@Description,@Specification,@Note)"
.Parameters.Add("@Code", txtEqCode.Text)
.Parameters.Add("@Plateno", txtVichNo.Text)
.Parameters.Add("@Serialno", txtCods.Text)
.Parameters.Add("@Model", txtModel.Text)
.Parameters.Add("@ki", txt_eq_type.Text)
.Parameters.Add("@Description", txt_eq_des.Text)
.Parameters.Add("@Specification", txtSpec.Text)
.Parameters.Add("@Note", txtRemark.Text)
End With
danew.InsertCommand.ExecuteNonQuery()


and it give an error .. can anybody help me with that plz..


Regards
 
Mr. fpineda101

The following is the code i used and the msg error...

VB.NET:
Try
If (txtEqCode.Text <> "" AndAlso txtVichNo.Text <> "") Then
With danew.InsertCommand
.CommandText = "INSERT INTO new_equip (eqcode, plateno, seralno,model,ki,Description,spec,Note) VALUES (@eqcode, @plateno,@seralno, @model,@ki,@Description,@spec,@Note)"
.Parameters.Add("@eqcode", txtEqCode.Text)
.Parameters.Add("@plateno", txtVichNo.Text)
.Parameters.Add("@seralno", txtCods.Text)
.Parameters.Add("@model", txtModel.Text)
.Parameters.Add("@ki", txt_eq_type.Text)
.Parameters.Add("@Description", txt_eq_des.Text)
.Parameters.Add("@spec", txtSpec.Text)
.Parameters.Add("@Note", txtRemark.Text)
End With
danew.InsertCommand.ExecuteNonQuery()
 
 
MsgBox("تمـت عمليـة الإضـافة بنجــاح", MsgBoxStyle.Exclamation, "")
Else
MessageBox.Show("لم تقم بإدخـال كـود المعـدة ورقمـها", " إدارة المعــدات", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
ClearTextBoxz()
 
Catch exception As System.Data.SqlClient.SqlException
MsgBox(exception.ToString, MsgBoxStyle.Critical)
 
End Try
 

Attachments

  • error.jpg
    error.jpg
    33.2 KB · Views: 81
Hey again,

Are you using an SQLCommand generated by Visual Studio?
Either way I'm pretty sure you should only be adding the parameters once after that you should use:

VB.NET:
Command1.Parameters("@param1").Value = "test"


Hope this helps,

Andy
 
Back
Top