Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 150,085 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,783 people online right now. Registration is fast and FREE... Join Now!




Wrong SQL command?

 
Reply to this topicStart new topic

Wrong SQL command?

cimpercee
20 Apr, 2008 - 11:01 PM
Post #1

D.I.C Head
**

Joined: 10 Aug, 2006
Posts: 127


My Contributions
Good day guys,
my problem is my DB doesn't insert. Please take a look @ my code.

CODE
   Dim conn As New SqlClient.SqlConnection(My.Settings.myConnectionString)
        Dim cmd As New SqlClient.SqlCommand
        Dim str As String
        str = "sp_addmao"
        With cmd
            .CommandType = CommandType.StoredProcedure
            .CommandText = str
            .Parameters.AddWithValue("@barangay", txtbox1.Text)
            .Parameters.AddWithValue("@umonth", txtbox2.Text)
            .Parameters.AddWithValue("@uyear", txtbox3.Text)
            .Parameters.AddWithValue("@useason", txtbox4.Text)
            .Parameters.AddWithValue("@ucategory", txtbox5.Text)
            .Parameters.AddWithValue("@hybridarea", h1.Text)
            .Parameters.AddWithValue("@hybridfarmers", h2.Text)
            .Parameters.AddWithValue("@certifiedarea", c1.Text)
            .Parameters.AddWithValue("@certifiedfarmers", c2.Text)
            .Parameters.AddWithValue("@goodarea", g1.Text)
            .Parameters.AddWithValue("@goodfarmers", g2.Text)
            .Parameters.AddWithValue("@totalarea", totalarea.Text)
            .Parameters.AddWithValue("@totalfarmers", totalfarmers.Text)
            .Connection = conn
        End With
        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()


MY SP

CODE
ALTER PROCEDURE sp_addmao
@barangay  varchar(50),
@umonth  varchar(50),
@uyear  varchar(50),
@useason  varchar(50),
@ucategory  varchar(50),
@hybridarea varchar(50),
@hybridfarmers  varchar(50),
@certifiedarea  varchar(50),
@certifiedfarmers  varchar(50),
@goodarea  varchar(50),
@goodfarmers  varchar(50),
@totalarea  varchar(50),
@totalfarmers  varchar(50)

AS
Insert INTO mao
& #40;barangay,umonth,uyear,useason,ucategory,hybridarea,hybridfarmers,certifiedar
ea,certifiedfarmers,
goodarea,goodfarmers,totalarea,totalfarmers)
Values
& #40;@barangay,@umonth,@uyear,@useason,@ucategory,@hybridarea,@hybridfarmers,@cer
tifiedarea,@certifiedfarmers,
@goodarea,@goodfarmers,@totalarea,@totalfarmers);


i hope you can help me.





This post has been edited by cimpercee: 20 Apr, 2008 - 11:41 PM
User is offlineProfile CardPM
+Quote Post

cimpercee
RE: Wrong SQL Command?
21 Apr, 2008 - 01:18 AM
Post #2

D.I.C Head
**

Joined: 10 Aug, 2006
Posts: 127


My Contributions
it seems my parameter doesn't pass value from textbox to the stored procedure.

don't know how to resolve my error as of now and i hope you can help me.
User is offlineProfile CardPM
+Quote Post

bflosabre91
RE: Wrong SQL Command?
21 Apr, 2008 - 05:09 AM
Post #3

D.I.C Head
**

Joined: 22 Feb, 2008
Posts: 245



Thanked: 1 times
My Contributions
try using this

CODE

Dim sql As New SqlCommand("sp_addmao", conn)
        sql.CommandType = CommandType.StoredProcedure

        ' Set the store procedure parameters for the data
        Dim barangay As New SqlParameter
        With barangay
            .ParameterName = "@barangay"
            .SqlDbType = SqlDbType.Char
            .Value = txtbox1.Text
        End With
        sql.Parameters.Add(barangay)


and do that for all your parameters.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 11:44PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month