give me code for selecting itemcode and correspondin vendor
details wll displays in the gridview?



give me code for selecting itemcode and correspondin vendor details wll displays in the gridview?..

Answer / sree11

Imports System.Data
Imports System.Data.SqlClient
Imports System.Windows.Forms
Public Class ItemVendorReport
Dim da As New SqlDataAdapter
Dim itemcode As String
Private Function getitemid(ByVal itemcode As String)
Dim itemid As Integer
da = New SqlDataAdapter("select item_id from
item_master where item_refid='" & itemcode & "'", Con)
Dim ds As New DataSet
da.Fill(ds)
If ds.Tables(0).Rows.Count > 0 Then
itemid = ds.Tables(0).Rows(0).Item(0).ToString()
End If
Return itemid
End Function
'Show the vendor details from vendor_details tables by
enter the itemid in txt_ItemId.
Private Sub btn_show_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btn_show.Click
clear_toolstrip()
If txt_ItemId.Text <> ""
Then 'verify the ItemId textbox value empty
or not
itemcode = txt_ItemId.Text.Trim
Dim itemid1 As String
itemid1 = getitemid(itemcode)
da = New SqlDataAdapter("select v.vendor_refid
as VendorCode,v.company_name as
CompanyName,v.firstcontactperson as
FirstContactPerson,v.mobno as MobileNo,v.address as
Address,v.city as City,v.state as State,v.country as
Country,v.pincode as PinCode,v.phone1 as PhoneNo1,v.phone2
as PhoneNo2,v.fax as Fax,v.email as EmailId,v.website As
WebSite from vendor_details v,vendor_item i where
i.vendor_id=v.vendor_id and i.item_id=" & itemid1 & " order
by v.vendor_id", Con)
Dim ds As New DataSet
da.Fill(ds, "vendorDetails")
dgv_View.DataSource = ds.Tables("vendorDetails")

dgv_View.AlternatingRowsDefaultCellStyle.BackColor =
Color.Bisque
For Each column As DataGridViewColumn In
dgv_View.Columns
column.SortMode =
DataGridViewColumnSortMode.NotSortable 'making
disable sorting of all columns
Next

For rowcount = 1 To dgv_View.Columns.Count - 1
dgv_View.Columns(rowcount).ReadOnly = True
Next
dgv_View.Columns(0).ReadOnly = False
dgv_View.Columns(0).Width = 50

dgv_View.Columns(0).ReadOnly = False
If ds.Tables("vendorDetails").Rows.Count = 0
Then 'verify macthing vendor details exists in the
database or not.
Stl_text.Text = "Invalid ItemId"
Stl_Image.Image = My.Resources.Red
Stl_text.ForeColor = Color.Red

End If
End If
End Sub
'Purpose :To Clear Toolstrip Messages and Images
Private Sub clear_toolstrip()
Stl_Image.Image = Nothing
Stl_text.Text = ""
End Sub
'Purpose : Selects All the records in datagridview
Private Sub lnk_Selectall_LinkClicked(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles
lnk_Selectall.LinkClicked
clear_toolstrip()
Dim Counter As Integer
For Counter = 0 To dgv_View.RowCount - 1
dgv_View.Item(0, Counter).Value = True
Next
End Sub
'Purpose : DeSelects All the records in datagridview
Private Sub lnk_Deselectall_LinkClicked(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles
lnk_Deselectall.LinkClicked
clear_toolstrip()
Dim Counter As Integer
For Counter = 0 To dgv_View.RowCount - 1
dgv_View.Item(0, Counter).Value = False
Next
End Sub
'Purpose : Calls when the export link clicked
Private Sub lnk_Export_LinkClicked(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles
lnk_Export.LinkClicked
clear_toolstrip()
Dim fn As String
Dim counter, rowcount As Integer
For counter = 0 To dgv_View.Rows.Count - 1
If dgv_View.Rows(counter).Cells(0).Value = True
Then
rowcount += 1
End If
Next
If rowcount > 0 Then
dlg_save.Filter = "Excel files (*.xls)|*.xls"
dlg_save.ShowDialog()
fn = dlg_save.FileName
If fn = "" Then
Exit Sub
End If
exporttoexcel_fromdgv(Me, dgv_View, fn, "Vendor
Details Report")
Else
Stl_text.Text = "Select atleast one record"
Stl_text.ForeColor = Color.Red
Stl_Image.Image = My.Resources.Red
End If
End Sub
'Purpose : Print the Datagridview records
Private Sub lnk_Print_LinkClicked(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles
lnk_Print.LinkClicked
clear_toolstrip() 'for clearing the status
strip
PrintDGV.Print_DataGridView(dgv_View)
End Sub
'Purpose : for clear the toolstrip values
Private Sub lnk_Selectall_Leave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
lnk_Selectall.Leave
clear_toolstrip() 'for clearing the status
strip
End Sub
'Purpose : for clear the toolstrip values
Private Sub lnk_Deselectall_Leave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
lnk_Deselectall.Leave
clear_toolstrip() 'for clearing the status
strip
End Sub
'Purpose : for clear the toolstrip values
Private Sub lnk_Export_Leave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
lnk_Export.Leave
clear_toolstrip() 'for clearing the status
strip
End Sub
'Purpose : for clear the toolstrip values
Private Sub lnk_Print_Leave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
lnk_Print.Leave
clear_toolstrip() 'for clearing the status
strip
End Sub
'purpose: for showing ErrorMessage
Private Sub txt_ItemId_Validating(ByVal sender As
System.Object, ByVal e As
System.ComponentModel.CancelEventArgs) Handles
txt_ItemId.Validating
If txt_ItemId.Text = "" Then
Errp.SetError(txt_ItemId, "Enter item Id")
Else
Errp.SetError(txt_ItemId, "")
End If
End Sub
'for allowing numbers only in the ItemId textbox
Private Sub txt_ItemId_KeyPress(ByVal sender As
System.Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
txt_ItemId.KeyPress
e.KeyChar = AllowNumber(e.KeyChar.ToString)
End Sub
'for clearing the status strip
Private Sub txt_ItemId_Leave(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
txt_ItemId.Leave
clear_toolstrip() 'for clearing the
status strip
End Sub
End Class

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More VB.NET Interview Questions

What is MSIL

8 Answers  


What would you do to remove microsoft visual basic name space?

0 Answers  


Explain the difference between an xml "fragment" and an xml "document."

0 Answers  


What do you mean by serialization and deserialization and it's use.

0 Answers  


Regarding Types of compatability in VB and their usage ?

1 Answers   Satyam,






What is sorting in vb?

0 Answers  


What is the main purpose of garbage collector?

0 Answers  


Write program in VB.Net with SQL Server and Crystal Reports to develop a small windows application to add,edit,save, search and print Employee Information and send sourcecode as zip file. empcode : .............. empname : .............. dateofjoin : dd/mm/yyyy dateofbirth : dd/mm/yyyy TableName: EmpMaster EmpCode EmpName DOB DOJ TableName: EmpDocs EmpCode DocNo DocName ExpDate

0 Answers   TCS,


is ADO.NET important to connect sql server? is any other way to connect sql server?

1 Answers  


Write a program that accepts an array of numbers and a number, and return a string “Yes” if the number is found in the array, “No” if the number is not found in the array.

2 Answers  


Disadvantages of vb ?

12 Answers   Digital GlobalSoft, TCS,


Explain about globalization?

0 Answers  


Categories