|
Hi,
1.
this is not the right forum for this. Your code might be Pascal, it certainly isn't Visual Basic.
2.
I don't know the answer, I would however try again without the '@' in line 154
3.
yes, I use line numbers to my advantage, and so should you; tell your IDE to show line numbers, look at such details when the compiler or run-time reports problems, and when you post, indicate which line has what line number of interest.
|
|
|
|
|
This is Pascal, not VB. Maybe the Delphi forum would have been better for this question. Anyway:
ST is declared as array[1..MaxEntry] of Symbol
TabPtr is declared as ^SymTab (pointer to SymTab)
T parameter in Lookup function is declared as TabPtr -- ^SymTab
So, declare ST as SymTab and it should work.
|
|
|
|
|
|
Hi All,
I'm writing a simple sql editor for our solid databases, and after the information has been retrieved I need to be able to display the field lenght for the column on the Database.
I fill the datagridview like this:
Private Sub applysql(ByVal query As String, Optional ByVal transaction As Odbc.OdbcTransaction = Nothing)<br />
Try<br />
Dim command As New Odbc.OdbcCommand(query, solid, transaction)<br />
datareader = command.ExecuteReader<br />
<br />
bindingsource.DataSource = datareader<br />
resultsdatgdvw.DataSource = bindingsource<br />
resultsdatgdvw.Update()<br />
resultsdatgdvw.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader)<br />
resultslbl.Text = "Returned " & resultsdatgdvw.RowCount & " rows"<br />
If Rollbackbtn.Enabled = False Then<br />
transaction.Commit()<br />
End If<br />
<br />
datareader.close()<br />
datareader.dispose()<br />
Catch ex As Exception<br />
MsgBox(ex.Message)<br />
End Try<br />
End Sub
and then wnat to display the tooltip with the information on like this:
Private Sub resultsdatgdvw_CellToolTipTextNeeded(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellToolTipTextNeededEventArgs) Handles resultsdatgdvw.CellToolTipTextNeeded<br />
If e.ColumnIndex > -1 Then<br />
e.ToolTipText = "Type: " & resultsdatgdvw.Columns(e.ColumnIndex).ValueType.ToString & " Length: " & 'Here is where I need to find the max length of the field <br />
End If<br />
End Sub
Any help appreciated!
Chris
|
|
|
|
|
Chris,
to get the metadata for the database objects, i think you need to look at using sys.Objects/sys.Columns in your query. Probably simpler if you add a sp to the db and call that.
I don't speak Idiot - please talk slowly and clearly
'This space for rent'
Driven to the arms of Heineken by the wife
|
|
|
|
|
Hi thanks for the advice (although I don't have a clue what a 'sp' is!)
I found the info I needed in the following way:
once I retirved the data and updated the datagrid view I created a seperate datatable and filled it with the schema table of the datareader
bindingsource.DataSource = datareader
resultsdatgdvw.DataSource = bindingsource
resultsdatgdvw.Update()
resultsdatgdvw.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.ColumnHeader)
Dim datatable As New DataTable
datatable = datareader.GetSchemaTable()
This puts the metadata for the columns into a table. I then looped round the rows in this table (each row being a column in the datareader) using each rows 'ItemArray' property to first map the row to the column header in the datagrid - ItemArray(0) - and then getting the type - via the datagrids column valuetype - and then maxlength - ItemArray(2) - and then nullable boolean - ItemArray(8).
I added all of this to the header cell of the column corresponding to the row in the datagrid view (I removed the tooltip from the other cells)
For Each row As DataRow In datatable.Rows
Try
resultsdatgdvw.Columns(row.ItemArray(0).ToString).HeaderCell.ToolTipText = "Type: " & resultsdatgdvw.Columns(row.ItemArray(0).ToString).ValueType.ToString.Replace("System.", "") & " Length: " & row.ItemArray(2).ToString & " Nullable: " & row.ItemArray(8).ToString
Catch ex As Exception
End Try
Next
datatable.Dispose()
For some reason the 'key' value in the ItemArray didn't return the correct value but I'm guessing that's just the database I'm using..
Chris
|
|
|
|
|
The file saved by this sub contains only a black rectange of the correct size. I have also tried bmp and jpg with same results.
I am using Vista 64 bit operating system and Visual Studio 2010, Traget CPU: x64, Traget FRamework: .NET Framework 4.
Private Sub MAIN_paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim tHeights, tWidth As Integer
'Define the text and layout
Dim txt As String = "Verdicrete Countertops"
Dim the_Font As New Drawing.Font("Helvetica", 28.5, FontStyle.Regular, GraphicsUnit.Pixel)
Dim string_size As SizeF = e.Graphics.MeasureString(txt, the_Font)
tHeights = CInt(string_size.Height)
tWidth = CInt(string_size.Width)
Dim Bitmap As New System.Drawing.Bitmap(tWidth, tHeights)
Using gr As Graphics = Graphics.FromImage(Bitmap)
Dim objBrushBackColor As New SolidBrush(Color.White)
'writes to bitmap and hence the file saved
gr.DrawString(txt, the_Font, Brushes.Black, 0, 0)
' writes to screen only
e.Graphics.DrawString(txt, the_Font, Brushes.Black, 0, 0)
Bitmap.Save("c:\windows\temp\Verdicrete.gif", System.Drawing.Imaging.ImageFormat.gif)
End Using
Bitmap.Dispose()
End Sub
modified on Sunday, December 5, 2010 7:03 PM
|
|
|
|
|
...and what does this mean? A hex dump of an image files tells us nothing.
What do you mean "does not save image"?? What DOES happen? What is expected to happen? Are there any expections? What are those messages? What exactly are you trying to save? Do you have an alpha channel? What format are you trying to save in? and, the MOST important thing, WHAT IS THE CODE YOUR USING TO SAVE THE FILE?
|
|
|
|
|
I HAVE UPDATED MY POST TO INCLUDED MY CODE.
|
|
|
|
|
Ok, but NO NEED TO SHOUT about it!
|
|
|
|
|
Sorry...didn't notice cap lock on.
|
|
|
|
|
Hi,
I see you are new here, so welcome to CodeProject.
When you encounter a problem, you can ask here, and expect a number of people to try and help you; however you have to help them help you by asking a clear question, giving some context, explaining what it is you are trying and what exactly is going on and not to your liking. In this case you should explain how you are saving the image ("using program so-and-so", or "with the following code"), how you are trying to open that image again ("using program so-and-so", or "with the following code"), and then describe what exactly makes you decide it does not work. Is there an exception thrown? show it to us. etc.
With the little you provided we can not determine whether the problem, if any, is in saving the image, or in reading the image. You can't expect someone to type your hex stuff into an app to check whether it is a legal image file...
BTW: if you show a code snippet, make sure to use PRE tags, such as provided by the "code block" widget (and not CODE tags!)
|
|
|
|
|
I HAVE POST MY CODE TO THIS POST.
|
|
|
|
|
OK,
1. the initial state of a new Bitmap is all black, which corresponds to pixels with R=G=B=0, so no surprise you won't see the text from DrawString at all. Start fill a FillRectangle of the required color, probably Brushes.White
2. Not sure why the ellipse would not show. Maybe you looked over it.
3. Transparency is tricky, I hardly ever use it. Some image formats can't handle it and will ignore it, others will deal with it OK. I suggest you perform your initial experiments without transparency.
4. You have some more objects that need disposing: a Font, a Graphics.
|
|
|
|
|
Thank you for your assistance. I made the change you suggested and got a white rectangle but no text. Any suggestions?
Private Sub MAIN_paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
Dim tHeights, tWidth As Integer
'Define the text and layout
Dim txt As String = "Verdicrete Countertops"
Dim the_Font As New Drawing.Font("Helvetica", 28.5, FontStyle.Regular, GraphicsUnit.Pixel)
Dim string_size As SizeF = e.Graphics.MeasureString(txt, the_Font)
tHeights = CInt(string_size.Height)
tWidth = CInt(string_size.Width)
Dim rect As New System.Drawing.Rectangle
rect.Width = tWidth
rect.Height = tHeights
Dim Bitmap As New System.Drawing.Bitmap(tWidth, tHeights)
Using gr As Graphics = Graphics.FromImage(Bitmap)
Dim objBrushBackColor As New SolidBrush(Color.White)
gr.FillRectangle(Brushes.White, rect)
e.Graphics.DrawString(txt, the_Font, Brushes.Black, 0, 0)
Bitmap.Save("c:\windows\temp\Verdicrete.gif", System.Drawing.Imaging.ImageFormat.Gif)
End Using
Bitmap.Dispose()
End Sub
|
|
|
|
|
just noticed, you (obviously) did round the MeasureString size from float to int, so now the text no longer fits and will get shortened/reduced to only show what fits. Try adding a few pixels to tHeights and tWidth.
BTW: you're still missing some Dispose() calls and PRE tags!
|
|
|
|
|
I'm trying to make a button that will search through a database and return a list of names of all the records matching a regular expression, plus data from a table if it exists. My first version looks like this:
Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
namesList.Items.Clear()
Me.MainTableAdapter.Connection.Open()
Dim myCommand As OleDbCommand = Me.MainTableAdapter.Connection.CreateCommand()
Me.MainTableAdapter.Transaction = Me.MainTableAdapter.Connection.BeginTransaction()
myCommand.Connection = Me.MainTableAdapter.Connection
myCommand.Transaction = Me.MainTableAdapter.Transaction
myCommand.CommandText = "Select * from main WHERE Title Like '%" & nameTB.Text & "%' order by title asc, ID asc"
Dim dbReader As OleDbDataReader = myCommand.ExecuteReader
While dbReader.Read()
Dim title As String = dbReader("Title")
Dim ID As Integer = dbReader("ID")
Dim qualifier As String = getQualifier(ID, Me.QualifiersTableAdapter)
If Not qualifier Is Nothing Then
title &= "- " & qualifier &
End If
namesList.Items.Add(title)
End While
Me.MainTableAdapter.Connection.Close()
End Sub
Private Function getQualifier(ByVal TitleID As Integer, ByVal adapter As QualifiersTableAdapter) As String
adapter.Connection.Open()
Dim myCommand As OleDbCommand = adapter.Connection.CreateCommand()
adapter.Transaction = adapter.Connection.BeginTransaction
myCommand.Connection = adapter.Connection
myCommand.Transaction = adapter.Transaction
myCommand.CommandText = "Select * from Qualifiers WHERE Title = " & TitleID
Dim dbReader As OleDbDataReader = myCommand.ExecuteReader
myCommand.Transaction.Commit()
Dim s as String = Nothing
If dbReader.Read() Then
s = dbReader("Qualifier")
End If
adapter.Connection.Close()
Return s
End Function
This works, but it's slow if the regular expression has lots of matches. So I revised it, moving the opening and closing of the table adapter to the button click function, so that they only get performed once each time you click the search button, instead of once for every record in the DB.
(modified since original post, problem still occurs)
Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
namesList.Items.Clear()
Dim dBaseConnectionString As String = "Provider=Microsoft.jet.oledb.4.0;" & _
"Data Source=demo.mdb" & ";"
Dim dBaseConnection As New OleDbConnection(dBaseConnectionString)
dBaseConnection.Open()
Dim dBaseCommand As New OleDbCommand("Select * from main WHERE Title Like '%" & titleTB.Text & "%' order by title asc, ID asc", dBaseConnection)
Dim dBaseDataReader As OleDb.OleDbDataReader = dBaseCommand.ExecuteReader()
While dBaseDataReader.Read()
Dim title As String = dbReader("Title")
Dim ID As Integer = dbReader("ID")
Dim qualifier As String = getQualifier(ID, dBaseConnection)
If Not qualifier Is Nothing Then
title &= "- " & qualifier &
End If
namesList.Items.Add(title)
End While
Me.MainTableAdapter.Connection.Close()
End Sub
Private Function getQualifier(ByVal TitleID As Integer, ByVal dBaseConnection As OleDbConnection) As String
Dim dBaseCommand As New OleDbCommand("Select * from Qualifiers WHERE Title = " & TitleID, dBaseConnection)
Dim dBaseDataReader As OleDb.OleDbDataReader = dBaseCommand.ExecuteReader()
If dbReader.Read() Then
Return dbReader("Qualifier")
Else
Return Nothing
End If
End Function
This is much faster. But I just realized something - if I use the search button enough times, I get an unhandled exception at myCommand.ExecuteReader , "Cannot open any more tables." It works fine once, even if I leave the regex blank and return everything in the database. With the old approach, I can hit the search button as many times as I want without seeing this exception.
So, what am I doing wrong here? I will admit I'm not totally comfortable with oledb and am only dimly aware of what my code is actually doing, so if you have any miscellaneous tips on how to use it better, I will listen.
Thanks.
modified on Sunday, December 5, 2010 2:50 PM
|
|
|
|
|
i_kant_spel wrote: Me.MainTableAdapter.Transaction = Me.MainTableAdapter.Connection.BeginTransaction()
I can't find any termination of that transaction inside SearchButton_Click; try adding a Commit.
BTW: I'm a bit puzzled by the double Connection.Open/Close; and by your transactions, do you need them at all?
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
modified on Sunday, December 5, 2010 5:49 AM
|
|
|
|
|
Added
myCommand.Transaction.Commit() below the button click function's Dim dbReader As OleDbDataReader = myCommand.ExecuteReader . It didn't make a difference.
Luc Pattyn wrote:
I can't find any termination of that transaction inside SearchButton_Click; try adding a Commit.
There's a good chance I've got oledb completely wrong, but I'm trying to read from two tables, so I thought I needed two table adapters, and both of them have connection properties.
It did occur to me that both adapters could share the same connection, so I changed the first function to this:
Private Sub SearchButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SearchButton.Click
namesList.Items.Clear()
myCommand.CommandText = "Select * from main WHERE Title Like '%" & nameTB.Text & "%' order by title asc, ID asc"
Dim dbReader As OleDbDataReader = myCommand.ExecuteReader
Dim myCommand As OleDbCommand = Me.MainTableAdapter.Connection.CreateCommand()
Me.MainTableAdapter.Transaction = Me.MainTableAdapter.Connection.BeginTransaction()
myCommand.Connection = Me.MainTableAdapter.Connection
myCommand.Transaction = Me.MainTableAdapter.Transaction
myCommand.CommandText = "Select * from main WHERE Title Like '%" & nameTB.Text & "%' order by title asc, ID asc"
Dim dbReader As OleDbDataReader = myCommand.ExecuteReader
myCommand.Transaction.Commit()
'stuff
Me.MainTableAdapter.Connection.Close()
End Sub
Same issue, though.
|
|
|
|
|
I'm no database expert, however I have several remarks for you:
1. I don't know why you are using transactions; the code shown only reads some data.
2. You could google "cannot open any more tables" and see a number of hits. I suggest you read a dozen of them and see if any of them ring a bell.
3. a number of database experts recommend against DataAdapters and in favor of DataReaders; you seem to mix both.
4. I would keep the code as simple as possible; only add something when you really have to.
5. You may want to provide more context when asking a question here. For instance, what has succeeded so far, how many tables/connections/transactions went well before things go wrong.
|
|
|
|
|
1 & 3 & 4:
Ok, I rewrote a big amount of the code. There are no transactions, no adapters, no strongly-typed datasets. See the original post for the new code. It still has the same problem.
2:
Yeah, I did this before posting here. I couldn't find anything that seemed to apply to my situation.
5:
If I leave titleTB.Text blank and click the search button, it will find everything in the database. This always works the first time. If I click it a second time, sometimes it works, sometimes it doesn't. IIRC, it always fails by the fifth time.
I've added some counters to the dataReader function lines, and ran it until it crashed, and looked at the counters.
The first executeReader occurs 3 times.
The first Read occurs 1320 times.
The second executeReader occurs 1319 times.
The second Read occurs 120 times.
|
|
|
|
|
i_kant_spel wrote: The first Read occurs 1320 times.
The second executeReader occurs 1319 times.
OK, you need some Dispose() calls.
While the garbage collector will eventually collect whatever objects you no longer need, it is wise to call Dispose() on those objects that are no longer in use and are instances of a class that offers a public Dispose(). This helps the system to cope with unmanaged resources, and to behave better when using scarce resources. It would not apply to objects you did not create yourself or didn't order creation of (such as PaintEventArgs.Graphics in a Paint handler).
It does apply to OleDbCommand and OleDbDataReader.
|
|
|
|
|
OleDbDataReader doesn't have a Dispose, but it does have a Close. I tried adding that to the end of the getQualifier function. Seems to have worked.
Thanks!
|
|
|
|
|
You're welcome.
|
|
|
|
|
Hi
Iam using sql server 2008. While saving time Iam getting trouble to show the size for varchar(max) field...
From the below Item_Description is Varchar(Max)
Therefore, how to pass the parameter size?......
My commands..
=============
Dim Ins_Save As String = "insert into Stock_Master (item_code,item_name,item_description) values (@item_code,@item_name,@item_description)"
MyDataAdapter.InsertCommand = New SqlCommand(Ins_Save, con)
With MyDataAdapter.InsertCommand.Parameters
.Add("@item_code", SqlDbType.VarChar, 15, "item_code")
.Add("@item_name", SqlDbType.VarChar, 30, "item_name")
.Add("@item_description", SqlDbType.VarChar, ?????????????????????, "item_description")
End With
Thanks For The Ideas
Regards
PARAMU
|
|
|
|
|