|
here is a pretty cool site that converts vb to c# and vica versa - its not perfect it sure beats typing everything out -
http://www.developerfusion.com/utilities/convertvbtocsharp.aspx
|
|
|
|
|
Personaly I use SharpDevelop[^] which has a built in C# to VB.Net and VB.Net to c# converter. I use it a lot as I write in VB.Net as work and C# at home. It is quicker to convert whole classes than to rewrite from scratch, even though the conversion is only 99% perfect.
|
|
|
|
|
Note that this function is not very efficient. Why is b1 an integer to begin with? And as for reading a single byte at a time...
my blog
|
|
|
|
|
Hi, I want to display the data from Ms access database (ex: Northwind.mdb) to a DataGrid control in VB.Net by using the code only. I don't want to bind the datagrid to any data control. Is it possible to do that? If it is possible can any one give me some sample code to work with it? Now I learn how to bind the data grid with Data Adapter configuration wizard, but i think it is not flexible like the code.
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
This should get you on the right track. Personally I like using the wizards but I use my own commands with the adapters and datasets that the wizard creates. This code works but don't like how it displays data in the datagrid. Maybe you can work it out. Enjoy
Dim oCmd As New OleDb.OleDbCommand()
Dim oDA As New OleDb.OleDbDataAdapter(oCmd)
Dim oDS As New DataSet()
Dim strCommand As String
Dim oConn As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Northwind.mdb;Mode=ReadWrite; Persist Security Info=False")
strCommand = "SELECT * FROM <table name>"
Try
oConn.Open()
With oCmd
.CommandType = CommandType.Text
.Connection = oConn
.CommandText = strCommand
End With
Catch ex As Exception
MessageBox.Show("Failed to connect to data source")
Finally
oConn.Close()
End Try
oDS.Clear()
oDA.Fill(oDS)
DataGrid1.DataSource = oDS Let me know if you can't get this to work. Remember to use your own connection path and in the command string use the table name you are selecting from.
|
|
|
|
|
Dear Britnt7, Thank you very much for your sample code. Now it is working and I will learn to customize it as much as I can. But I have one more question. I put your give that give to me on the form load, and the data fill in the datagrid as I want but the grid is not display until I click on the plug sign (+) then it display the data as I want. Do you know how to ignore this plus sign? I mean when the form load with your code I can see the data display directly in the datagrid without click the plus sign to see the data in the grid. Thank you very much for your help!!!
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Dear Britnt7, I have one more question. In VB6 when I transfer the data from database to list view control, I have an opportunity to give the name of the column header to a difference name from the field of the table in database but I can use do while ... loop to put the data one by one in the list view. But the datagrid in VB.net seem that have no opportunity to code to change the name of the column, is it true? The reason is the database that I design is written in my own language. The field of the table written in English while the record is written in my own language. So when I display on the grid it display in english only so the column header could read in english but the record could not read. But when I change the font to my language the record could read (know the meaning) but the column header could not read. Any possible solution?
A thousand mile of journey, begin with the first step.
APO-CEDC
Save Children Norway-Cambodia Office
|
|
|
|
|
Hi..
Can anybosy telll me a gud site or a tutorial to know about web class libraries.I have a couple of pages that are common to quite a number of applications.
So would like to add them into a library storing at one places and calling them from various applications.Is it possible??
Thanks in anticipation
g
|
|
|
|
|
Hello,I have the following project and I have tried and tried but can't seem to get it. Can anyone help?
I have to write a program to campare the secant method with newton's method for finding the roots of each function:
x^3 - 3x + 1 with starting point Xo=2
x^3 - 2 sin x with starting point Xo=.5
The instructions also state to use the X1 value from Newton's method as the second starting point for the secant method and to print out each iteration for both methods. I appreciate any help.
|
|
|
|
|
L_JIMENEZ wrote:
I have tried and tried
What have you tried ? Where are you having trouble ?
L_JIMENEZ wrote:
I appreciate any help.
Sure, but no-one is going to do your homework for you. If you can post what you've got, and where you're stuck, we're all glad to help out.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
the purpose of this code is to display data in specific textboxes when a user click on any items in listbox ... this one i'm coding for web application.
but actually, it doesn't work at all ... i could not figure out the problems ...
could anyone there help me please?
thanks in advance
Private Sub activateform()
Dim mlstoneDreader As OleDb.OleDbDataReader
Dim mlstoneCommand As OleDb.OleDbCommand
Dim slect As String
Dim StSQl As String
Dim ConnStr As String
ConnStr = BuildSQLConnection()
slect = lstmilestone.SelectedItem.Value
StSQl = "Select staffId, LastName, FirstName, Email "
StSQl &= " From Staff "
StSQl &= " where staffId = " & slect
Try
mlstoneCommand = New OleDb.OleDbCommand()
With mlstoneCommand
.Connection = New OleDb.OleDbConnection(ConnStr)
.Connection.Open()
.CommandText = StSQl
mlstoneDreader = .ExecuteReader(CommandBehavior.SingleRow)
End With
If mlstoneDreader.Read() Then
With mlstoneDreader
txtid.Text = .Item("StaffId").ToString()
txtmlname.Text = .Item("LastName").ToString()
txtdesc.Text = .Item("FirstName").ToString()
End With
Else
ClearAll()
End If
mlstoneDreader.Close()
mlstoneCommand.Connection.Close()
Catch mlstone_e As Exception
MsgBox("Connection failed")
End Try
End Sub
Private Sub ClearAll()
txtid.Text = " "
txtmlname.Text = " "
txtdesc.Text = " "
txtnoofday.Text = " "
End Sub
|
|
|
|
|
Fired Dragon wrote:
but actually, it doesn't work at all ... i could not figure out the problems ...
Why not ? i.e. what doesn't it do ? Have you traced through to see what is going into your SQL ? Run your SQL in query analyser to make sure it should return the values you expect ? etc.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
hi christ
although, data displays in a listbox, when i select items in the listbox, it doesn't display in the textboxes.
i've ran my sql in query analyser, the results show out correctly.
could you help me to solve out please?
|
|
|
|
|
You say it's a web application - when you click on an item in the listbox, does it postback ? Have you put breakpoints in to verify that your code is being called ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Public Class milestone
Inherits System.Web.UI.Page
Protected WithEvents btnadd As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
Protected WithEvents btnmodify As System.Web.UI.WebControls.Button
Protected WithEvents Btndelete As System.Web.UI.WebControls.Button
Protected WithEvents txtmlname As System.Web.UI.WebControls.TextBox
Protected WithEvents txtnoofday As System.Web.UI.WebControls.TextBox
Protected WithEvents lstmilestone As System.Web.UI.WebControls.ListBox
Protected WithEvents txtid As System.Web.UI.WebControls.TextBox
Protected WithEvents txtdesc As System.Web.UI.WebControls.TextBox
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<system.diagnostics.debuggerstepthrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
InitializeComponent()
Listmilestone()
'Put user code to initialize the page here
End Sub
Private Function Listmilestone()
Dim mlstoneDreader As OleDb.OleDbDataReader
Dim mlstoneCommand As OleDb.OleDbCommand
Dim slect As Web.UI.WebControls.ListBox
Dim StSQl As String
Dim ConnStr As String
ConnStr = BuildSQLConnection()
StSQl = " Select staffId, FirstName "
StSQl &= " From staff"
mlstoneCommand = New OleDb.OleDbCommand()
With mlstoneCommand
.Connection = New OleDb.OleDbConnection(ConnStr)
.Connection.Open()
.CommandText = StSQl
mlstoneDreader = .ExecuteReader(CommandBehavior.SequentialAccess)
End With
lstmilestone.Items.Clear()
Do While mlstoneDreader.Read()
lstmilestone.Items.Add(mlstoneDreader.Item("Firstname"))
Loop
mlstoneDreader.Close()
If lstmilestone.Items.Count > 0 Then
lstmilestone.SelectedIndex = 0
End If
mlstoneDreader.Close()
mlstoneCommand.Connection.Close()
End Function
Private Sub lstmilestone_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstmilestone.SelectedIndexChanged
activateform()
End Sub
Private Sub activateform()
Dim mlstoneDreader As OleDb.OleDbDataReader
Dim mlstoneCommand As OleDb.OleDbCommand
Dim slect As String
Dim StSQl As String
Dim ConnStr As String
ConnStr = BuildSQLConnection()
slect = lstmilestone.SelectedItem.Value
StSQl = "Select staffId, LastName, FirstName, Email "
StSQl &= " From Staff "
StSQl &= " where staffId = " & slect
Try
mlstoneCommand = New OleDb.OleDbCommand()
With mlstoneCommand
.Connection = New OleDb.OleDbConnection(ConnStr)
.Connection.Open()
.CommandText = StSQl
mlstoneDreader = .ExecuteReader(CommandBehavior.SingleRow)
End With
If mlstoneDreader.Read() Then
With mlstoneDreader
txtid.Text = .Item("StaffId").ToString()
txtmlname.Text = .Item("LastName").ToString()
txtdesc.Text = .Item("FirstName").ToString()
End With
Else
ClearAll()
End If
mlstoneDreader.Close()
mlstoneCommand.Connection.Close()
Catch mlstone_e As Exception
MsgBox("Connection failed")
End Try
End Sub
Private Sub ClearAll()
txtid.Text = " "
txtmlname.Text = " "
txtdesc.Text = " "
txtnoofday.Text = " "
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
milestoneAdd()
End Sub
Private Sub milestoneAdd()
Dim stSQL As String
Dim mlstoneCommand As OleDb.OleDbCommand
Dim milestone_Rows As Integer
Dim SQLConn As New Clsconnection()
stSQL = "INSERT INTO ProjectMilestone "
stSQL &= " Id, "
stSQL &= " Description, "
Try
mlstoneCommand = New OleDb.OleDbCommand()
With mlstoneCommand
.Connection = New OleDb.OleDbConnection(BuildSQLConnection())
.Connection.Open()
.CommandText = stSQL
milestone_Rows = .ExecuteNonQuery()
If milestone_Rows <> 1 Then
MsgBox("Did not insert row")
End If
.Connection.Close()
End With
Catch oException As Exception
MsgBox(oException.Message)
End Try
End Sub
Private Function BuildSQLConnection() As String
Dim ConnStr As String
ConnStr = "Provider=sqloledb"
ConnStr &= ";Data Source=(local)"
ConnStr &= ";Initial Catalog=PROMAN"
ConnStr &= ";User ID=sa"
ConnStr &= ";Password=hien"
Return ConnStr
End Function
End Class
|
|
|
|
|
I'd prefer if you answered my question - does the page postback ? Does your event handler get called ?
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
no, it doesnt, when i click on an item in the listbox, it doesnot postback anything to the textboxes,
Does your event handler get called ? yeah, it does
|
|
|
|
|
Fired Dragon wrote:
no, it doesnt, when i click on an item in the listbox, it doesnot postback anything to the textboxes,
Postback is what we ASP.NET developers call it when the page posts back to the server. If your event is being called, postback is occuring.
You obviously haven't stepped through the code. Your code looks like this:
Private Sub lstmilestone_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstmilestone.SelectedIndexChanged<br />
activateform()<br />
End Sub
Now, why would this event handler do a jolly thing, when there's no code in it ? The code in activate form needs to be moved into the event handler.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
i've moved the code in "activateform" into "lstmilestone_SelectedIndexChanged" but unfortunately, it doesnot work as i planed
Christ, i appreciate for what you've help me honestly.
|
|
|
|
|
I need more info than 'it doesn't work as I planned'. Have you stepped through the code ? Have you checked what the SQL you're generating looks like ? Is the SQL OK ? What result are you getting ?
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
i have steped through the code, i've used 'step into' but it's jumped to Exception in the event handler 'lstmilestone_SelectedIndexChanged'
my SQL is ok, it shows out staffID, lastname, firstnam, email ... etc
i've already tried to find the problems for a week. it's really stressful
|
|
|
|
|
Fired Dragon wrote:
it's jumped to Exception in the event handler 'lstmilestone_SelectedIndexChanged'
Where in the event handler, exactly ?
Fired Dragon wrote:
my SQL is ok, it shows out staffID, lastname, firstnam, email ... etc
I'm talking about the SQL that's generated by the event handler. Have you checked that ? Does it get that far ?
slect = lstmilestone.SelectedItem.Value
for starters you should check if SelectedItem is null before attempting this.
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
If mlstoneDreader.Read() Then
With mlstoneDreader
txtid.Text = .Item("StaffId").ToString()
txtmlname.Text = .Item("LastName").ToString()
txtdesc.Text = .Item("FirstName").ToString()
End With
Else
ClearAll()
End If
mlstoneDreader.Close()
mlstoneCommand.Connection.Close()
'step into jumping to
Catch mlstone_e As Exception
MsgBox(mlstone_e.Message)
End Try
my sql doesnt get any problems here, Christ. and i've watched variable 'slect', it has had value inside,
|
|
|
|
|
What is the error message you are getting ?
Have you checked the state of the reader ( that is, is it set up with a valid connection, etc. )
Christian
I have several lifelong friends that are New Yorkers but I have always gravitated toward the weirdo's. - Richard Stringer
|
|
|
|
|
Fired Dragon wrote:
this is all what i have done, it may make you more visible
yes i am now more visible than before, thanks i hadn't seen my left arm for years
|
|
|
|