zeeshanef's Profile
Reputation: 17
Tradesman
- Group:
- Active Members
- Active Posts:
- 68 (0.17 per day)
- Joined:
- 14-April 12
- Profile Views:
- 690
- Last Active:
Apr 30 2013 07:27 AM- Currently:
- Offline
Previous Fields
- Country:
- PK
- OS Preference:
- Who Cares
- Favorite Browser:
- Opera
- Favorite Processor:
- Intel
- Favorite Gaming Platform:
- Who Cares
- Your Car:
- Who Cares
- Dream Kudos:
- 0
Posts I've Made
-
In Topic: Adding New Record To Database And View in Datagrid
Posted 15 Feb 2013
your first method seems good, but you need to Open connection before execute query!
try this:
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click Dim sql As String Dim cmd As SqlCommand Dim cons As String Dim con As SqlConnection cons = "Data Source=.\SQLSERVER2008;AttachDbFilename=|DataDirectory|\ProductsDatabase.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True" con = New SqlConnection(cons) sql = "Insert into Products(ProductCode, ItemName, Size, SRP, WholeSalePrice, OriginalPrice, Availability, Color, Description, Supplier)" & _ "values (@ProductCode, @ItemName, @Size, @SRP, @WholeSalePrice, @OriginalPrice, @Availability, @Color, @Description, @Supplier)" cmd = New SqlCommand(sql, con) cmd.Parameters.Add("@ProductCode", SqlDbType.NChar, 10).Value = Me.ProductCodeTextBox.Text.Trim cmd.Parameters.Add("@ItemName", SqlDbType.NVarChar, 50).Value = Me.ItemNameTextBox.Text.Trim cmd.Parameters.Add("@Size", SqlDbType.NChar, 10).Value = Me.SizeTextBox.Text.Trim cmd.Parameters.Add("@SRP", SqlDbType.NChar, 10).Value = Me.SRPTextBox.Text.Trim cmd.Parameters.Add("@WholeSalePrice", SqlDbType.NChar, 10).Value = Me.WholeSalePriceTextBox.Text.Trim cmd.Parameters.Add("@OriginalPrice", SqlDbType.NChar, 10).Value = Me.OriginalPriceTextBox.Text.Trim cmd.Parameters.Add("@Availability", SqlDbType.Bit).Value = avail cmd.Parameters.Add("@Color", SqlDbType.NVarChar, 50).Value = Me.ColorTextBox.Text.Trim cmd.Parameters.Add("@Description", SqlDbType.NVarChar).Value = Me.DescriptionTextBox.Text.Trim cmd.Parameters.Add("@Supplier", SqlDbType.NVarChar).Value = Me.SupplierTextBox.Text.Trim Try con.Open() cmd.ExecuteNonQuery() formMain.ProductsTableAdapter.Update(formMain.ProductsDatabaseDataSet.Products) formMain.ProductsDatabaseDataSet.AcceptChanges() MsgBox("New Record Saved! ") Catch ex As Exception MsgBox(ex.ToString) Finally If con.State = ConnectionState.Open Then con.Close() End Try End Sub -
In Topic: Help with VB.Net and MySQL: Next/Previous Record
Posted 10 Dec 2012
1.
If your are using Visual Studio 2010 or greater, you can implement automatic property like:
Public Property CompanyID As Integer
else, you need to implement property like this:
private _companyID as Integer = 0 Property CompanyID As Integer Get Return _companyID End Get Set(ByVal value As Integer) _companyID = value End Set End Property
See this Link:
http://msdn.microsof...y/dd293589.aspx
2.
In your next button you can do something like this:
TextBox1.Text = clientsList(n++).CompanyID
And you will also check, if Index is Out of Bound. -
In Topic: There is already an open DataReader associated with this Command
Posted 4 Dec 2012
If you want to check, if ID already exists in database, then why are you using datareader try it with Executescaler.
Dim sqlcmdccheck As New SqlCommand("Select count(*) From Customer_Table WHERE C_Code=@CustomerCode, sqlcon) sqlcmdccheck.Parameters.AddWithValue("@CustomerCode", Trim(CustomerCodeTextBox.Text)) Dim count As Int32 = Convert.Int32(sqlcmdccheck.ExecuteScalar()) If(count <= 0) 'Insert End If -
In Topic: Help with VB.Net and MySQL: Next/Previous Record
Posted 3 Dec 2012
when you do "While DR.Read", data reader goes through all records and last one will be shown in textboxes.
to get records you need to create List(of T).
1. Create a class:
Public Class Clients 'Create properties as your data fields Public Property CompanyID As Integer Public Property CompanyName As String 'and all your fields End Class
2.
Create a class level List object, so that it will be accessible in your class:
Dim clientsList As New List(Of Clients)
3. in your loop:
While DR.Read Dim addClient As New Clients addClient.CompanyID = DR.Item("CompanyID") addClient.CompanyName = DR.Item("CompanyName") 'and all your fields 'Add object into list clientsList.Add(addClient) End While
Now you have all records in clientsList.
your First record will be:
TextBox1.Text = clientsList(0).CompanyID TextBox2.Text = clientsList(0).CompanyName
and last record will be:
TextBox1.Text = clientsList(clientsList.Count - 1).CompanyID TextBox2.Text = clientsList(clientsList.Count - 1).CompanyName
-
In Topic: how do i capture tab key
Posted 3 Dec 2012
There is a Property with controls, TabIndex.
Set Tab order as you need like:
Textbox.TabIndex=0; Combobox.TabIndex=1;
My Information
- Member Title:
- D.I.C Head
- Age:
- Age Unknown
- Birthday:
- Birthday Unknown
- Gender:
-
Contact Information
- E-mail:
- Private
Friends
|
|


Find Topics
Find Posts
View Reputation Given

|
Comments
zeeshanef has no profile comments yet. Why not say hello?