can not add a record to a db table using the vb.net and ado.net

Hi

 

I am trying to insert record to Pups Database using ado.net and vb.net in a windows application.

This form will collect data from user to insert it into stores table at Pubs database (storeID, name, address etc..).

I am not able to get the new inserted record into the stores table

here is my coude behind for the form

Imports System.Data.SqlClient

 

Public Class ParametersExample

Inherits System.Windows.Forms.Form

Dim con As SqlConnection

 

Private Sub addBttn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles addBttn.Click

Dim cmd As SqlCommand = New SqlCommand()

Dim iRowsAffected As Integer

con = New SqlConnection()

con.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PUBS.MDF;Integrated Security=True;User Instance=True"

cmd.CommandText = "spInsertStore"

cmd.CommandType = CommandType.StoredProcedure

cmd.Connection = con

cmd.Parameters.Add(
"@stor_id", SqlDbType.Char, 4)

cmd.Parameters.Item("@stor_id").Value = txtID.Text

cmd.Parameters.Add("@stor_name", SqlDbType.VarChar, 40)

cmd.Parameters.Item("@stor_name").Value = txtName.Text

cmd.Parameters.Add("@stor_address", SqlDbType.VarChar, 40)

cmd.Parameters.Item("@stor_address").Value = txtAddress.Text

cmd.Parameters.Add("@city", SqlDbType.VarChar, 20)

cmd.Parameters.Item("@city").Value = txtCity.Text

cmd.Parameters.Add("@state", SqlDbType.VarChar, 2)

cmd.Parameters.Item("@state").Value = txtState.Text

cmd.Parameters.Add("@zip", SqlDbType.Char, 5)

cmd.Parameters.Item("@zip").Value = txtZip.Text

cmd.Parameters.Add("@current_count", SqlDbType.Int)cmd.Parameters.Item("@current_count").Direction = ParameterDirection.Output

 

con.Open()

iRowsAffected = cmd.ExecuteNonQuery()

con.Close()

Dim iCurrentCount As Integer

iCurrentCount = cmd.Parameters.Item("@current_count").ValueMsgBox("the current count is: " & iCurrentCount)

 

End Sub

End Class

 

 

and the stored procedure to access table is here

ALTER PROCEDURE dbo.spInsertStore

/*

(

@parameter1 int = 5,

@parameter2 datatype OUTPUT

)

*/

 

@stor_id
as char(4),

@stor_name as varchar(40),

@stor_address as varchar(40),

@city as varchar(20),

@state as char(2),

@zip as char(5),

@current_count as int OUTPUT

AS

INSERT
stores (stor_id,

stor_name,

Stor_address,

city,

state,

zip)

VALUES (@stor_id,

@stor_name,

@stor_address,

@city,

@state,

@zip)

SELECT @current_count = Count(*) FROM stores

 

I Do get the msgbox display the number of records of the table, but I can not see the newley enterd record added to the table.

(I do refresh the Pubs database after each entry)

why I am not being able to insert the new record?

 

Thanks

0
Mubarak_100
9/10/2008 2:04:02 AM
asp.net.getting-started 91979 articles. 4 followers. Follow

4 Replies
1212 Views

Similar Articles

[PageSpeed] 56

 You need to rebind the datagridview to it's datasource. One question...if you close the app and rerun it, do you see the data you insert before closing?

One more note, these forums are for asp.net. For windows apps, you're better off going to www.windowsclient.net. They have a good support community too. Good luck Big Smile

0
HeartattacK
9/10/2008 3:07:44 AM

HeartattacK:

 You need to rebind the datagridview to it's datasource. One question...if you close the app and rerun it, do you see the data you insert before closing?

One more note, these forums are for asp.net. For windows apps, you're better off going to www.windowsclient.net. They have a good support community too. Good luck Big Smile

hi

No, if i close the app and rerun it, still I get the same old result, and the record is not inserted.

thanks

 

0
Mubarak_100
9/11/2008 2:23:59 AM

Do you have the .mdb file added to your solution? If so, right click it in solution explorer and select properties. See if "copy to output" is set to always or not. If it is, change it.

0
HeartattacK
9/11/2008 4:31:54 AM

hi Heartattack, thanks again for responding

yes I have done that, Initially the copy to output is set to aways, so I did not change it, but still does not solve the problem.

 

Bests

 

 

0
Mubarak_100
9/23/2008 8:31:27 PM
Reply:

Similar Artilces:

Sending SMS using vb.net or C#.net using vb.net or c#.net
Hi  My requirement is I hav one csv file with these fields id,mobilenum,messgae,status.intiallu staus is 0. once i read the all fileds and take that mobile number.using tat mobile number  i need to send sms .after sending sms i shuld change status as 1 How to send sms thru coding (please dont provide any links.if it is provide also please give working links becox i checked codeproject .i didnt get any nice link. and also provide the how to update the status field im csv file   Thank ssandhya   To send SMS, you need some third party SMS providers. if you consul...

how can i write this line using vb.net : container.dataitem ?.... in vb.net its not working
Dim container As GridView = CType(newLinkButton.NamingContainer, GridView) Dim dataValue As Object = DataBinder.Eval(container.dataitem, _ColName)   _ColName its just a string a name of the field in my database   This is Vb.Net code man what you want? You can convert any format from this link http://www.developerfusion.com/tools/convert/vb-to-csharp/  If this post is answer of your question then don't forgot to Click Mark As Answer...

use VB.NET and C#.NET code in the same C#.NET project
All-- Here is a sample that is "off the beaten path", (at least for me). Is it possible, in an ASP.NET application, using the code-behind page building technique, to have both pages written in VB.NET and pages written C#.NET?At http://www.WebLogicArts.com/DemoList.aspx there is a sample that shows that, (contrary to popular belief), it IS possible to mix ASP.NET pages built with C#.NET with ASP.NET pages built with VB.NET in the same VS.NET 2003 project. Note that this is just a "fun" sample to see if it can be done and I do not recommend this practice as a "standard" way of develo...

Insert datetime, using ADO.net VB.net
Hello there,I got a little code there are inserting a record into my msSQL database..But i cant insert the datetime, for one reason?The problem is in line 7 () where i want to insert DateTime.Now 1 Protected Sub SendPmTilAfviste(ByVal modtager As String, ByVal festID As String) 2 ' Connection 3 Dim conn As SqlConnection = New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True") 4 conn.Open() 5 6 ' SQL-kommandoen 7 Dim cm...

How to Add Applications to ADAM using vb.net or C#.net
 Hi Pls thrown light  any one on How to Add Applications to ADAM using vb.net or C#.net RegardsMallikarjunaP.Mallikarjuna...

ADO.NET table fields pass to a VB.NET variable
Hi, please help, have a ADO.NET code. 1 Dim conn As New Data.SqlClient.SqlConnection 2 Dim sql As New Data.SqlClient.SqlCommand 3 4 conn = New Data.SqlClient.SqlConnection("Provider=SQLOLEDB.1;Password=dbsystematics;Persist Security Info=True;User ID=sa;Initial Catalog=SARS;Data Source=4G") 5 conn.Open() 6 sql = New Data.SqlClient.SqlCommand("select * from users", conn)   Then i would like to pass the values that the above ADO.NET to a variable.how?please help. JFRBPH12™ You can execute the ...

How can i return the 5 records from a database table using ado.net
I have an incident reporting management application. People are supposed to report incidents by this application and every time some one reports an incident, they also select thier employee#(reqiured field). so how can write an sql statement that returns only the Top 5 incident reporters i.e going by employee number. Iam thinking of applying a COUNT function on the incident_id and grouping by Employee# but then how do i make sure that only the top 5 incident reporters are returned.--------------------------------------------------No Project Too Eazy.------------------------------------------...

ADO in VB6 vs ADO.NET in VB.NET
I am writing a database interface and I would like to know whether a VB6 interface using ADO or a VB.NET interface using ADO.NET would be faster in terms of just performing database operations. Is there an explanation for this, and what is the magnitude of the difference? Thanks in advance!...

how can i Get OCX File in .net IDE vb.net/C3
hi all,      How can I generate OCX file in VB.net/c# 2005 that will interact in web pages...?Thanks & Regards,Murthy. Hi murthysrn, As far as I know, VB 2005 and C# 2005 cannot create the project for ocx file. However, I hope the following link will be helpful to you. Creating an ActiveX Control in Visual Studio 2005http://msmvps.com/blogs/pauldomag/archive/2006/08/16/107758.aspxSincerely,Benson YuMicrosoft Online Community Support Please remember to mark the replies as answers if they help and unmark them if they provide no help. This can be beneficial to other co...

How benificial is it to use VS.NET? Can I do just as well with VB.NET?
How benificial is it to use VS.NET? Can I do just as well with VB.NET? I'm probably going to be moving from handcoding with HomeSite and ASP Classic to ASP.NET. From all I read VS.NET seems the tool of choice but expensive. Will VB.NET do just as well if all I plan to write is VB code? Any other good choices? Thanks As far as i know there is no Product" entitled vb.net. Visual Studio.Net 2002/2003 differs from it's non .net predesser (mental block, cant spell - sorry) in that all technologies (ie. VB, c# C++, J#) are developed from within the one application(IDE). There...

use of vb.net and c#.net
i make a small website using vb.net,  in it i make a 2 class in C#.net. that i want to use in that website, i dont know how to call that class. let your class is  - class clsMyClass    {        public void myFunction()        {            // do something        }    } now the first way - create objectclsMyClass myObj = new clsMyClass();myObj.myFunction(); // call function================...

used a c#.net to vb.net converter and am now getting a syntax error.
ok I used a cool utility at http://www.kamalpatel.net/ConvertCSharp2VB.aspx to convert some c#.net to vb.net and it spit out a bunch of code which almost works but I am getting a syntax error on this line Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) I tried it that way and also like Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) but either way gave the same error Compiler Error Message: BC30035: Syntax error. Source Error: Line 26: Line ...

converting to vb.net from c#.net authorize.net
authorize.net offered me some sample code when I signed up with them the only problem is the sample code is in c#.net but my page that they type all of their credit card into is vb.net <code><%@ Import Namespace="System.Net" %> <%@ Import Namespace="System.IO" %> <script language="C#" runat="server"> void Page_Load(Object Src, EventArgs E) { myPage.Text = readHtmlPage("https://certification.authorize.net/gateway/transact.dll"); } private String readHtmlPage(string url) { ...

What can c#.net do that vb.net can't?
That's pretty much my question - what can you do with c#, in terms of web application building, that you can't do in vb.net? Thanks Which language you choose is pretty much up you, your preferences and previous experience. There are some differences, but most importantly one have to realize that all .Net compliant languages are translated into an Intermediate Language and at the end of the day, what run is pretty much the same. Read this if you need to know more: "Microsoft Programming Languages" http://msdn.microsoft.com/vstudio/productinfo/whitepapers/default.aspx ...