Public CrReport As Object
CrystalReportViewer1.ReportSource = CrReport
Dim Myform As New FrmSuppLedgerPreview
Dim DSPrint As New DSCLedgerPrint
DSPrint.Tables.Clear()
DSPrint.Tables.Add(Print_Detail())
Dim XReport As New CrSLDetail
XReport.SetDataSource(DSPrint)
Myform.CrReport = XReport
Myform.Show(Me)
All query regarding the .Net programming. Find the solution of all the problems regarding coding.
How to apply transaction in typed dataset
Imports Microsoft.VisualBasic
Imports System.Data.SqlClient
Namespace DSBatchTableAdapters
Partial Public Class BatchMasterTableAdapter
Dim _Transaction As SqlTransaction
Public Property Transaction() As SqlTransaction
Get
Return _Transaction
End Get
Set(ByVal value As SqlTransaction)
_Transaction = value
_connection = _Transaction.Connection
If _adapter Is Nothing Then
Me.InitAdapter()
End If
For Each command As SqlCommand In Me.CommandCollection
command.Transaction = _Transaction
Next
Me.Adapter.InsertCommand.Transaction = _Transaction
Me.Adapter.UpdateCommand.Transaction = _Transaction
Me.Adapter.DeleteCommand.Transaction = _Transaction
End Set
End Property
Public Sub SetCommandTimeOut(ByVal PassTime As Integer)
For Each Command As SqlCommand In Me.CommandCollection
Command.CommandTimeout = PassTime
Next
End Sub
End Class
Partial Public Class BatchChildTableAdapter
Dim _Transaction As SqlTransaction
Public Property Transaction() As SqlTransaction
Get
Return _Transaction
End Get
Set(ByVal value As SqlTransaction)
_Transaction = value
_connection = _Transaction.Connection
If _adapter Is Nothing Then
Me.InitAdapter()
End If
For Each command As SqlCommand In Me.CommandCollection
command.Transaction = _Transaction
Next
Me.Adapter.InsertCommand.Transaction = _Transaction
Me.Adapter.UpdateCommand.Transaction = _Transaction
Me.Adapter.DeleteCommand.Transaction = _Transaction
End Set
End Property
Public Sub SetCommandTimeOut(ByVal PassTime As Integer)
For Each Command As SqlCommand In Me.CommandCollection
Command.CommandTimeout = PassTime
Next
End Sub
End Class
End Namespace
Imports System.Data.SqlClient
Namespace DSBatchTableAdapters
Partial Public Class BatchMasterTableAdapter
Dim _Transaction As SqlTransaction
Public Property Transaction() As SqlTransaction
Get
Return _Transaction
End Get
Set(ByVal value As SqlTransaction)
_Transaction = value
_connection = _Transaction.Connection
If _adapter Is Nothing Then
Me.InitAdapter()
End If
For Each command As SqlCommand In Me.CommandCollection
command.Transaction = _Transaction
Next
Me.Adapter.InsertCommand.Transaction = _Transaction
Me.Adapter.UpdateCommand.Transaction = _Transaction
Me.Adapter.DeleteCommand.Transaction = _Transaction
End Set
End Property
Public Sub SetCommandTimeOut(ByVal PassTime As Integer)
For Each Command As SqlCommand In Me.CommandCollection
Command.CommandTimeout = PassTime
Next
End Sub
End Class
Partial Public Class BatchChildTableAdapter
Dim _Transaction As SqlTransaction
Public Property Transaction() As SqlTransaction
Get
Return _Transaction
End Get
Set(ByVal value As SqlTransaction)
_Transaction = value
_connection = _Transaction.Connection
If _adapter Is Nothing Then
Me.InitAdapter()
End If
For Each command As SqlCommand In Me.CommandCollection
command.Transaction = _Transaction
Next
Me.Adapter.InsertCommand.Transaction = _Transaction
Me.Adapter.UpdateCommand.Transaction = _Transaction
Me.Adapter.DeleteCommand.Transaction = _Transaction
End Set
End Property
Public Sub SetCommandTimeOut(ByVal PassTime As Integer)
For Each Command As SqlCommand In Me.CommandCollection
Command.CommandTimeout = PassTime
Next
End Sub
End Class
End Namespace
How to dictinct record from the data table by data view
Dim CustTable As New DataTable
Dim DTable As New DataTable
CustTable = Return_CustomerTable()
Dim DView As New DataView(CustTable)
DView.Sort = "Name"
DTable = DTV.ToTable()
Dim DTable As New DataTable
CustTable = Return_CustomerTable()
Dim DView As New DataView(CustTable)
DView.Sort = "Name"
DTable = DTV.ToTable()
How to track the checkbox status of the check list box
Dim Count As Decimal = 0
If ChkCC.CheckedItems.Count > 0 Then
For Count = 0 To ChkCC.Items.Count - 1
If ChkCC.GetItemChecked(Count) = True Then
Count = Count + 1
End If
Next
End If
MsgBox(Count & " items checked.")
If ChkCC.CheckedItems.Count > 0 Then
For Count = 0 To ChkCC.Items.Count - 1
If ChkCC.GetItemChecked(Count) = True Then
Count = Count + 1
End If
Next
End If
MsgBox(Count & " items checked.")
How to dictinct record from the data table by data view
Dim Col(0) As String
Col(0) = "CustName"
Dim CustTable As New DataTable
Dim DTable As New DataTable
CustTable = Return_CustomerTable()
Dim DTV As New DataView(CustTable)
DTable = DTV.ToTable(True, Col)
Col(0) = "CustName"
Dim CustTable As New DataTable
Dim DTable As New DataTable
CustTable = Return_CustomerTable()
Dim DTV As New DataView(CustTable)
DTable = DTV.ToTable(True, Col)
How to Open image from byte array
Dim Gimage As Byte()
Dim TempPath As String
Dim FileName As String = "Image.jpg"
Gimage = Return_ImageByte()
TempPath = System.IO.Path.GetTempPath()
System.IO.File.WriteAllBytes(TempPath & FileName, Gimage)
System.Diagnostics.Process.Start(TempPath & FileName)
Dim TempPath As String
Dim FileName As String = "Image.jpg"
Gimage = Return_ImageByte()
TempPath = System.IO.Path.GetTempPath()
System.IO.File.WriteAllBytes(TempPath & FileName, Gimage)
System.Diagnostics.Process.Start(TempPath & FileName)
How to Read image from open file dialog in byte array
Dim GImage As Byte()
ReDim GImage(OpenFileDialog1.OpenFile.Length)
OpenFileDialog1.OpenFile.Read(GImage, 0, GImage.Length)
ReDim GImage(OpenFileDialog1.OpenFile.Length)
OpenFileDialog1.OpenFile.Read(GImage, 0, GImage.Length)
How to Show image in picture box from the byte array
Dim MStream As IO.MemoryStream
Dim GImage As Byte()
GImage = GetImageByte()
MStream = New System.IO.MemoryStream(GImage)
PictureBox1.Image = Image.FromStream(MStream)
Dim GImage As Byte()
GImage = GetImageByte()
MStream = New System.IO.MemoryStream(GImage)
PictureBox1.Image = Image.FromStream(MStream)
How to track the check box of the data grid view
Dim Y As DataGridViewCheckBoxCell
Dim Count As Decimal = 0
For Each DGVRow As DataGridViewRow In DataGridView1.Rows
Y = CType(DGVRow.Cells("Chk"), DataGridViewCheckBoxCell)
If Y.Value = True Then
Count = Count + 1
End If
Next
MsgBox(Count & " items checked.")
Dim Count As Decimal = 0
For Each DGVRow As DataGridViewRow In DataGridView1.Rows
Y = CType(DGVRow.Cells("Chk"), DataGridViewCheckBoxCell)
If Y.Value = True Then
Count = Count + 1
End If
Next
MsgBox(Count & " items checked.")
How to Allow only numeric value in the text box
Private Sub Txtopening_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Txtopening.KeyPress
If Asc(e.KeyChar) > 47 And Asc(e.KeyChar) < 58 Or Asc(e.KeyChar) = 8 Or Asc(e.KeyChar) = 46 Then
If Txtopening.Text.Contains(".") Then
If Asc(e.KeyChar) = 46 Then
e.Handled = True
End If
Else
e.Handled = False
End If
Else
e.Handled = True
End If
End Sub
If Asc(e.KeyChar) > 47 And Asc(e.KeyChar) < 58 Or Asc(e.KeyChar) = 8 Or Asc(e.KeyChar) = 46 Then
If Txtopening.Text.Contains(".") Then
If Asc(e.KeyChar) = 46 Then
e.Handled = True
End If
Else
e.Handled = False
End If
Else
e.Handled = True
End If
End Sub
How To bind the table with the combo box
Dim DTable As New DataTable
DTable = ReturnCustTable()
If DTable.Rows.Count > 0 Then
CmbBrand.DataSource = DTable
CmbBrand.ValueMember = DTable.Columns("CustID").ColumnName
CmbBrand.DisplayMember = DTable.Columns("CustName").ColumnName
End If
DTable = ReturnCustTable()
If DTable.Rows.Count > 0 Then
CmbBrand.DataSource = DTable
CmbBrand.ValueMember = DTable.Columns("CustID").ColumnName
CmbBrand.DisplayMember = DTable.Columns("CustName").ColumnName
End If
How Check all check box of list view on click Select all Check box
Private Sub ChkAll_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChkAll.CheckedChanged
If ChkAll.CheckState = CheckState.Checked Then
For Each X As ListViewItem In ListView1.Items
X.Checked = True
Next
Else
For Each X As ListViewItem In ListView1.Items
X.Checked = False
Next
End If
End Sub
If ChkAll.CheckState = CheckState.Checked Then
For Each X As ListViewItem In ListView1.Items
X.Checked = True
Next
Else
For Each X As ListViewItem In ListView1.Items
X.Checked = False
Next
End If
End Sub
How to add sub Item in the list view
Dim W As New ListViewItem
For Each DRow As DataRow In SuppTable.Rows
W.Text = SuppTable.Rows(0).Item("Name").ToString()
W.SubItems.Add(SuppTable.Rows(0).Item("Address").ToString())
ListView1.Items.Add(W)
Next
For Each DRow As DataRow In SuppTable.Rows
W.Text = SuppTable.Rows(0).Item("Name").ToString()
W.SubItems.Add(SuppTable.Rows(0).Item("Address").ToString())
ListView1.Items.Add(W)
Next
How to Read value from cell of data grid view
Dim CustName As String = ""
For Each drRow As DataGridViewRow In DGVAmount.Rows
CustName = drRow.Cells("CustName"). FormattedValue
Next
For Each drRow As DataGridViewRow In DGVAmount.Rows
CustName = drRow.Cells("CustName"). FormattedValue
Next
How to set max length in data grid view or handle data grid view keypress event
Private Sub DGVAmount_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DGVAmount.KeyPress
If DGVAmount.SelectedCells.Count > 0 Then
If DGVAmount.SelectedCells(0).ColumnIndex = DGVAmount.Columns("LfinalAmount").Index Then
Dim intMaxLength As Integer = 12 'Set your max length here
If dgvTxtBox Is Nothing = False Then
Dim str As String = dgvTxtBox.Text.ToString()
If Not str.Length < intMaxLength _
AndAlso Not e.KeyChar = ControlChars.Back Then
e.Handled = True
Beep()
Exit Sub
End If
End If
End If
End If
End Sub
If DGVAmount.SelectedCells.Count > 0 Then
If DGVAmount.SelectedCells(0).ColumnIndex = DGVAmount.Columns("LfinalAmount").Index Then
Dim intMaxLength As Integer = 12 'Set your max length here
If dgvTxtBox Is Nothing = False Then
Dim str As String = dgvTxtBox.Text.ToString()
If Not str.Length < intMaxLength _
AndAlso Not e.KeyChar = ControlChars.Back Then
e.Handled = True
Beep()
Exit Sub
End If
End If
End If
End If
End Sub
How to allow only numeric value to type in data grid view or handle data grid view keypress event
Private dgvTxtBox As DataGridViewTextBoxEditingControl
Private Sub DGVAmount_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DGVAmount.EditingControlShowing
Dim ctrlName As String = e.Control.GetType.Name
If ctrlName = "DataGridViewTextBoxEditingControl" Then
dgvTxtBox = CType(e.Control, DataGridViewTextBoxEditingControl)
AddHandler dgvTxtBox.KeyPress, AddressOf DGVAmount_KeyPress
dgvTxtBox.Enabled = True
End If
End Sub
‘------------------------------------------------------------------
Private Sub DGVAmount_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DGVAmount.KeyPress
If DGVAmount.SelectedCells.Count > 0 Then
If DGVAmount.SelectedCells(0).ColumnIndex = DGVAmount.Columns("LfinalAmount").Index Then
If dgvTxtBox Is Nothing = False Then
Dim str As String = dgvTxtBox.Text.ToString()
If Asc(e.KeyChar) > 47 And Asc(e.KeyChar) <= 57 Or e.KeyChar = "." Or Asc(e.KeyChar) = 8 Then
If str.Contains(".") Then
If Asc(e.KeyChar) = 46 Then
e.Handled = True
Else
e.Handled = False
End If
Else
e.Handled = False
End If
Else
e.Handled = True
End If
End If
End If
End If
End Sub
Private Sub DGVAmount_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles DGVAmount.EditingControlShowing
Dim ctrlName As String = e.Control.GetType.Name
If ctrlName = "DataGridViewTextBoxEditingControl" Then
dgvTxtBox = CType(e.Control, DataGridViewTextBoxEditingControl)
AddHandler dgvTxtBox.KeyPress, AddressOf DGVAmount_KeyPress
dgvTxtBox.Enabled = True
End If
End Sub
‘------------------------------------------------------------------
Private Sub DGVAmount_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles DGVAmount.KeyPress
If DGVAmount.SelectedCells.Count > 0 Then
If DGVAmount.SelectedCells(0).ColumnIndex = DGVAmount.Columns("LfinalAmount").Index Then
If dgvTxtBox Is Nothing = False Then
Dim str As String = dgvTxtBox.Text.ToString()
If Asc(e.KeyChar) > 47 And Asc(e.KeyChar) <= 57 Or e.KeyChar = "." Or Asc(e.KeyChar) = 8 Then
If str.Contains(".") Then
If Asc(e.KeyChar) = 46 Then
e.Handled = True
Else
e.Handled = False
End If
Else
e.Handled = False
End If
Else
e.Handled = True
End If
End If
End If
End If
End Sub
How to remove value from data grid view on press delete key or handle data grid view keydown event
Private Sub DGVAmount_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles DGVAmount.KeyDown
If DGVAmount.Rows.Count > 0 Then
If DGVAmount.SelectedCells(0).ColumnIndex = DGVAmount.Columns("LfinalAmount").Index Then
If e.KeyCode = Keys.Delete Then
DGVAmount.SelectedCells(0).Value = ""
End If
End If
End If
End Sub
If DGVAmount.Rows.Count > 0 Then
If DGVAmount.SelectedCells(0).ColumnIndex = DGVAmount.Columns("LfinalAmount").Index Then
If e.KeyCode = Keys.Delete Then
DGVAmount.SelectedCells(0).Value = ""
End If
End If
End If
End Sub
How to add row in the Data grid view one by one fron the datatable
For Each Dr As DataRow In RTable.rows
LCount = DGVAmount.Rows.Add()
DGVAmount.Rows(LCount).Cells("CustID").Value = Dr.Item("ID")
DGVAmount.Rows(LCount).Cells("CustName").Value = Dr.Item("Name")
Next
LCount = DGVAmount.Rows.Add()
DGVAmount.Rows(LCount).Cells("CustID").Value = Dr.Item("ID")
DGVAmount.Rows(LCount).Cells("CustName").Value = Dr.Item("Name")
Next
How to create Write only property
Dim DocID As Decimal
Public WriteOnly Property PassDocumentID()
Set(ByVal value)
DocID = value
End Set
End Property
Public WriteOnly Property PassDocumentID()
Set(ByVal value)
DocID = value
End Set
End Property
Creating Thumb Images
Public Function Generate_Thumb(ByVal GImage As Byte()) As Byte()
Dim Mstream As New System.IO.MemoryStream
Mstream.Write(GImage, 0, GImage.Length)
Dim BIMage As Bitmap
Dim Thumb As Bitmap
BIMage = Bitmap.FromStream(Mstream)
Thumb = CreateThumbNail(BIMage, 120, 120)
Dim imageStream As New System.IO.MemoryStream
Thumb.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim imageContent As Byte()
imageContent = imageStream.GetBuffer()
Return imageContent
End Function
‘---------------------------------------------------------
Private Function CreateThumbNail(ByVal postedFile As Bitmap, ByVal width As Integer, ByVal height As Integer) As Bitmap
Dim bmpOut As System.Drawing.Bitmap
Dim Ratio As Decimal
Dim NewWidth As Integer
Dim NewHeight As Integer
'*** If the image is smaller than a thumbnail just return it
If postedFile.Width < width AndAlso postedFile.Height < height Then
Return postedFile
End If
If (postedFile.Width > postedFile.Height) Then
Ratio = Convert.ToDecimal(width / postedFile.Width)
NewWidth = width
Dim Temp As Decimal = postedFile.Height * Ratio
NewHeight = Convert.ToInt32(Temp)
Else
Ratio = Convert.ToDecimal(height / postedFile.Height)
NewHeight = height
Dim Temp As Decimal = postedFile.Width * Ratio
NewWidth = Convert.ToInt32(Temp)
End If
bmpOut = New Bitmap(NewWidth, NewHeight)
Dim g As Graphics = Graphics.FromImage(bmpOut)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.FillRectangle(Brushes.White, 0, 0, NewWidth, NewHeight)
g.DrawImage(postedFile, 0, 0, NewWidth, NewHeight)
postedFile.Dispose()
Return bmpOut
End Function
Dim Mstream As New System.IO.MemoryStream
Mstream.Write(GImage, 0, GImage.Length)
Dim BIMage As Bitmap
Dim Thumb As Bitmap
BIMage = Bitmap.FromStream(Mstream)
Thumb = CreateThumbNail(BIMage, 120, 120)
Dim imageStream As New System.IO.MemoryStream
Thumb.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg)
Dim imageContent As Byte()
imageContent = imageStream.GetBuffer()
Return imageContent
End Function
‘---------------------------------------------------------
Private Function CreateThumbNail(ByVal postedFile As Bitmap, ByVal width As Integer, ByVal height As Integer) As Bitmap
Dim bmpOut As System.Drawing.Bitmap
Dim Ratio As Decimal
Dim NewWidth As Integer
Dim NewHeight As Integer
'*** If the image is smaller than a thumbnail just return it
If postedFile.Width < width AndAlso postedFile.Height < height Then
Return postedFile
End If
If (postedFile.Width > postedFile.Height) Then
Ratio = Convert.ToDecimal(width / postedFile.Width)
NewWidth = width
Dim Temp As Decimal = postedFile.Height * Ratio
NewHeight = Convert.ToInt32(Temp)
Else
Ratio = Convert.ToDecimal(height / postedFile.Height)
NewHeight = height
Dim Temp As Decimal = postedFile.Width * Ratio
NewWidth = Convert.ToInt32(Temp)
End If
bmpOut = New Bitmap(NewWidth, NewHeight)
Dim g As Graphics = Graphics.FromImage(bmpOut)
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
g.FillRectangle(Brushes.White, 0, 0, NewWidth, NewHeight)
g.DrawImage(postedFile, 0, 0, NewWidth, NewHeight)
postedFile.Dispose()
Return bmpOut
End Function
Access the crystal report text object in the code
Dim XReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument
Dim LText As Object
XReport.Load(Server.MapPath(".\Reports\CrPrint.rpt"), CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
LText = XReport.ReportDefinition.Sections("Section5").ReportObjects("TxtCreatedBy")
LText.text = "Printed By : Gaurav Agrawal"
Dim LText As Object
XReport.Load(Server.MapPath(".\Reports\CrPrint.rpt"), CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
LText = XReport.ReportDefinition.Sections("Section5").ReportObjects("TxtCreatedBy")
LText.text = "Printed By : Gaurav Agrawal"
How to create datatable from sqlreader
Public Function ReaderToTable(ByVal LReader As SqlDataReader) As Data.DataTable
Dim LTable As New Data.DataTable
Dim I As Integer
For I = 0 To LReader.FieldCount - 1
LTable.Columns.Add(LReader.GetName(I).ToString(), LReader.GetFieldType(I))
Next
Do While LReader.Read()
Dim DRow As DataRow
DRow = LTable.Rows.Add()
For I = 0 To LReader.FieldCount - 1
DRow.Item(LTable.Columns(I).ColumnName) = LReader.Item(I)
Next
Loop
LTable.TableName = "Reader"
Return LTable
End Function
Dim LTable As New Data.DataTable
Dim I As Integer
For I = 0 To LReader.FieldCount - 1
LTable.Columns.Add(LReader.GetName(I).ToString(), LReader.GetFieldType(I))
Next
Do While LReader.Read()
Dim DRow As DataRow
DRow = LTable.Rows.Add()
For I = 0 To LReader.FieldCount - 1
DRow.Item(LTable.Columns(I).ColumnName) = LReader.Item(I)
Next
Loop
LTable.TableName = "Reader"
Return LTable
End Function
How to print crystal Report
Public Function ReturnPrintReport(ByVal DocID As Decimal, ByVal PrintType As Decimal) As Byte()
Dim MastTable As New DataTable
Dim XReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
Dim ArrReport() As Byte
Dim LDS As New DataSet
Dim FileAttach As System.IO.MemoryStream
MastTable = Write_MastTable(DocID)
If MastTable.Rows.Count > 0 Then
LDS.Tables.Add(MastTable)
XReport.Load(Server.MapPath(".\Reports\CrPrint.rpt"), CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
XReport.SetDataSource(LDS)
Select Case PrintType
Case 1 'For Crystal Report
FileAttach = XReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.CrystalReport)
Case 2 'For PDF File
FileAttach = XReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
End Select
ArrReport = FileAttach.ToArray()
Else
ArrReport = Nothing
End If
Return ArrReport
End Function
Dim MastTable As New DataTable
Dim XReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument()
Dim ArrReport() As Byte
Dim LDS As New DataSet
Dim FileAttach As System.IO.MemoryStream
MastTable = Write_MastTable(DocID)
If MastTable.Rows.Count > 0 Then
LDS.Tables.Add(MastTable)
XReport.Load(Server.MapPath(".\Reports\CrPrint.rpt"), CrystalDecisions.Shared.OpenReportMethod.OpenReportByDefault)
XReport.SetDataSource(LDS)
Select Case PrintType
Case 1 'For Crystal Report
FileAttach = XReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.CrystalReport)
Case 2 'For PDF File
FileAttach = XReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat)
End Select
ArrReport = FileAttach.ToArray()
Else
ArrReport = Nothing
End If
Return ArrReport
End Function
How to write byte in the file
Dim Fs As System.IO.FileStream
Dim TempFileName As String
Dim RBytes() As Byte
TempFileName = System.IO.Path.GetTempFileName()
Fs = New System.IO.FileStream(TempFileName, IO.FileMode.Create, IO.FileAccess.Write)
Fs.Write(RBytes, 0, RBytes.Length)
Fs.Close()
Return TempFileName
Dim TempFileName As String
Dim RBytes() As Byte
TempFileName = System.IO.Path.GetTempFileName()
Fs = New System.IO.FileStream(TempFileName, IO.FileMode.Create, IO.FileAccess.Write)
Fs.Write(RBytes, 0, RBytes.Length)
Fs.Close()
Return TempFileName
How to set file size in KB,MB,Byte
Dim Size As Decimal = 0
Dim Title As String = ""
Dim TStr As String = ""
Dim FileSize As Decimal = 0
FileSize = PRow.Item("FileSize")
If FileSize > 1024 Then
If FileSize > 1024 * 1024 Then
Size = Decimal.Round(FileSize / (1024 * 1024), 2)
Title = " MB"
TStr = Size.ToString & Title
Else
Size = Decimal.Round(FileSize / 1024, 2)
Title = " KB"
TStr = Size.ToString & Title
End If
Else
Size = FileSize
Title = " Bytes"
TStr = Size.ToString() & Title
End If
Dim Title As String = ""
Dim TStr As String = ""
Dim FileSize As Decimal = 0
FileSize = PRow.Item("FileSize")
If FileSize > 1024 Then
If FileSize > 1024 * 1024 Then
Size = Decimal.Round(FileSize / (1024 * 1024), 2)
Title = " MB"
TStr = Size.ToString & Title
Else
Size = Decimal.Round(FileSize / 1024, 2)
Title = " KB"
TStr = Size.ToString & Title
End If
Else
Size = FileSize
Title = " Bytes"
TStr = Size.ToString() & Title
End If
How to insert the record in the table through AddWithValue
Dim SqlConn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ToString())
Dim OBjTrans As SqlTransaction = Nothing
Dim ObjCommand As New SqlCommand
SqlConn.Open()
ObjCommand.CommandText = "INSERT INTO CustMast(CustName) VALUES (@CustName)
ObjCommand.Parameters.AddWithValue("@CustName ","Gaurav Agrawal")
ObjCommand.Connection = SqlConn
ObjCommand.Transaction = OBjTrans
ObjCommand.ExecuteNonQuery()
ObjCommand.Dispose()
OBjTrans.Commit()
SqlConn.Close()
Dim OBjTrans As SqlTransaction = Nothing
Dim ObjCommand As New SqlCommand
SqlConn.Open()
ObjCommand.CommandText = "INSERT INTO CustMast(CustName) VALUES (@CustName)
ObjCommand.Parameters.AddWithValue("@CustName ","Gaurav Agrawal")
ObjCommand.Connection = SqlConn
ObjCommand.Transaction = OBjTrans
ObjCommand.ExecuteNonQuery()
ObjCommand.Dispose()
OBjTrans.Commit()
SqlConn.Close()
How to read only date from the sql database with time through Sql query
Select Count(*) From BillMast where Cast(Floor(Cast(BillDate as Float)) as datetime) = '" + Billdate.ToString("yyyy/MM/dd") + "'"
How to use Transaction for deleting the record
Deleting record in transaction
Dim SqlConn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ToString())
Dim OBjTrans As SqlTransaction = Nothing
Dim ObjCommand As New SqlCommand
SqlConn.Open()
OBjTrans = SqlConn.BeginTransaction()
ObjCommand.CommandText = "Delete From StockInMast WHERE RefNo =23 " ObjCommand.Connection = SqlConn
ObjCommand.Transaction = OBjTrans
ObjCommand.ExecuteNonQuery()
ObjCommand.Dispose()
OBjTrans.Commit()
SqlConn.Close()
SqlConn.Dispose()
Dim SqlConn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ToString())
Dim OBjTrans As SqlTransaction = Nothing
Dim ObjCommand As New SqlCommand
SqlConn.Open()
OBjTrans = SqlConn.BeginTransaction()
ObjCommand.CommandText = "Delete From StockInMast WHERE RefNo =23 " ObjCommand.Connection = SqlConn
ObjCommand.Transaction = OBjTrans
ObjCommand.ExecuteNonQuery()
ObjCommand.Dispose()
OBjTrans.Commit()
SqlConn.Close()
SqlConn.Dispose()
How to get current date with time in AM/PM format
Dim CurDate As String
CurDate = System.DateTime.UtcNow.ToString("dd/MM/yyyy hh:mm tt")
CurDate = System.DateTime.UtcNow.ToString("dd/MM/yyyy hh:mm tt")
Add DataTable in the Dataset
Dim LTable As New DataTable
Dim LDS As New DataSet
LDS.Tables.Add(LTable)
Dim LDS As New DataSet
LDS.Tables.Add(LTable)
How to read data from SqlReader
Read data from database through sqlreader
Dim CReader As SqlDataReader
Do While CReader.Read()
Dr = CTable.Rows.Add
Dr("StyleID") = CReader.Item("StyleID").ToString()
Dr("StyleCode") = CReader.Item("StyleCode").ToString()
Loop
Dim CReader As SqlDataReader
Do While CReader.Read()
Dr = CTable.Rows.Add
Dr("StyleID") = CReader.Item("StyleID").ToString()
Dr("StyleCode") = CReader.Item("StyleCode").ToString()
Loop
Set the column caption exist in the table
Set the Caption for the data column
Dim SizeTable As New DataTable("SizeTable")
SizeTable.Columns("Size").Caption = "Size Name"
Dim SizeTable As New DataTable("SizeTable")
SizeTable.Columns("Size").Caption = "Size Name"
How to Open connection where connection string exist in the web config file
Write the following code to open sqlconnection
Dim SqlConn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ToString())
SqlConn.Open()
Dim SqlConn As New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("MyConnectionString").ToString())
SqlConn.Open()
How to clear the string Builder object
To clear the String Builder Object write the following code
Dim LSql As New System.Text.StringBuilder
LSql.Length = 0
Dim LSql As New System.Text.StringBuilder
LSql.Length = 0
How to add Column in the Data Table
Write the following code to add the column in the data table named as "SizeTable"
SizeTable.Columns.Add("Size", GetType(String))
SizeTable.Columns.Add("ID", GetType(Decimal))
SizeTable.Columns.Add("Size", GetType(String))
SizeTable.Columns.Add("ID", GetType(Decimal))
Subscribe to:
Posts (Atom)