Skip to main content
deleted 39 characters in body; edited title
Source Link
Jamal
  • 35.2k
  • 13
  • 134
  • 238

Modified TextBox for Forms Generatingforms generating SQL Statements in VB.NETstatements

I've Inherited System.Windows.Forms.TextBoxinherited System.Windows.Forms.TextBox and added a few properties to help me out in creating forms that generate SQL statements.

I use to create a large function that would check for changes in the TextBoxTextBox compared to a string. Then it would take text and concatenate it to a SQL statement. Now it's simple and easier to use.

SQLTextBox.vbSQLTextBox.vb

Let me know what you think of this. I'm not sure if it's really anything someone could use, but it's been very useful to me.

Edit: So, I've pulled an excerpt from my code. It's not much, but here is the new textbox vs the old one.

In the SQL text, iI have something like ""Material Type"" in('INSERTTEXT'). SQLTextBox.ModifiedSQLTextBox.Modified gets set when the user leaves the textbox (set to false b default).

I went from 200 lines of code to 6, with a minor change. That does not include the lines spent setting up the default text or the.

Let me know what you think of this. I'm not sure if it's really anything someone could use, but it's been very useful to me.

Modified TextBox for Forms Generating SQL Statements in VB.NET

I've Inherited System.Windows.Forms.TextBox and added a few properties to help me out in creating forms that generate SQL statements.

I use to create a large function that would check for changes in the TextBox compared to a string. Then it would take text and concatenate it to a SQL statement. Now it's simple and easier to use.

SQLTextBox.vb

Let me know what you think of this. I'm not sure if it's really anything someone could use, but it's been very useful to me.

Edit: So, I've pulled an excerpt from my code. It's not much, but here is the new textbox vs the old one.

In the SQL text, i have something like ""Material Type"" in('INSERTTEXT'). SQLTextBox.Modified gets set when the user leaves the textbox (set to false b default).

I went from 200 lines of code to 6, with a minor change. That does not include the lines spent setting up the default text or the

Modified TextBox for forms generating SQL statements

I've inherited System.Windows.Forms.TextBox and added a few properties to help me out in creating forms that generate SQL statements.

I use to create a large function that would check for changes in the TextBox compared to a string. Then it would take text and concatenate it to a SQL statement. Now it's simple and easier to use.

SQLTextBox.vb

I've pulled an excerpt from my code. It's not much, but here is the new textbox vs the old one.

In the SQL text, I have something like ""Material Type"" in('INSERTTEXT'). SQLTextBox.Modified gets set when the user leaves the textbox (set to false b default).

I went from 200 lines of code to 6, with a minor change. That does not include the lines spent setting up the default text.

Let me know what you think of this. I'm not sure if it's really anything someone could use, but it's been very useful to me.

add excerpt
Source Link
CodeMonkey
  • 451
  • 1
  • 4
  • 12

Edit: So, I've pulled an excerpt from my code. It's not much, but here is the new textbox vs the old one.

In the SQL text, i have something like ""Material Type"" in('INSERTTEXT'). SQLTextBox.Modified gets set when the user leaves the textbox (set to false b default).

'This should run every new textbox (untested)
For i As Integer = 0 To Me._icControls.txtMain.Length - 1
    If Me._icControls.txtMain(i).Modified = True Then
        sqlWhere += " AND " + Me._icControls.txtMain(i).SqlText
        Replace(sqlWhere, "INSERTTEXT", Me._icControls.txtMain(i).Text)
    End If
Next

'Old, long way around where I had split up
'the textboxes into 7 groups they belonged too.
If Me._icControls.txtMaterial(0).Text.ToString() <> DefaultStrings.Material(0) Then
    sqlWhere += " AND ""Material Type"" in('" + Me._icControls.txtMaterial(0).Text.ToString() + "')"
End If

If Me._icControls.txtMaterial(4).Text.ToString() <> DefaultStrings.Material(4) Then
    sqlWhere += " AND ""Grade"" in('" + Me._icControls.txtMaterial(4).Text.ToString() + "')"
End If

If Me._icControls.txtMaterial(5).Text.ToString() <> DefaultStrings.Material(5) Then
    sqlWhere += " AND ""PIW"" in('" + Me._icControls.txtMaterial(5).Text.ToString() + "')"
End If

I went from 200 lines of code to 6, with a minor change. That does not include the lines spent setting up the default text or the

Edit: So, I've pulled an excerpt from my code. It's not much, but here is the new textbox vs the old one.

In the SQL text, i have something like ""Material Type"" in('INSERTTEXT'). SQLTextBox.Modified gets set when the user leaves the textbox (set to false b default).

'This should run every new textbox (untested)
For i As Integer = 0 To Me._icControls.txtMain.Length - 1
    If Me._icControls.txtMain(i).Modified = True Then
        sqlWhere += " AND " + Me._icControls.txtMain(i).SqlText
        Replace(sqlWhere, "INSERTTEXT", Me._icControls.txtMain(i).Text)
    End If
Next

'Old, long way around where I had split up
'the textboxes into 7 groups they belonged too.
If Me._icControls.txtMaterial(0).Text.ToString() <> DefaultStrings.Material(0) Then
    sqlWhere += " AND ""Material Type"" in('" + Me._icControls.txtMaterial(0).Text.ToString() + "')"
End If

If Me._icControls.txtMaterial(4).Text.ToString() <> DefaultStrings.Material(4) Then
    sqlWhere += " AND ""Grade"" in('" + Me._icControls.txtMaterial(4).Text.ToString() + "')"
End If

If Me._icControls.txtMaterial(5).Text.ToString() <> DefaultStrings.Material(5) Then
    sqlWhere += " AND ""PIW"" in('" + Me._icControls.txtMaterial(5).Text.ToString() + "')"
End If

I went from 200 lines of code to 6, with a minor change. That does not include the lines spent setting up the default text or the

Easier Readability
Source Link
CodeMonkey
  • 451
  • 1
  • 4
  • 12

I've taken the baseInherited System.Windows.Forms.TextBox and have modified itadded a littlefew properties to help me out in creating forms that generate SQL statements. 

I use to create a large function that would check for changes in the TextBox compared to a string. Then it would take that changed stringtext and concatenate it to a SQL statement. Now it's simple and easier to use. I

I've added two textfour properties that hold the SQL statement that the text is associated with and the default text displayed. I also added an ID integer for and needs to compare the IDs of textboxes and a boolean to check if the text was modified from the default string.:

  • A String property to hold the default string that the textbox is initially set to and will reset back if the text is left empty.
  • A String property to hold the text's associated SQL statement.
  • A Boolean to check if the text has changed from the default.
  • Finally, an Integer to hold an ID if there is a reason to need one, such as saving and loading text from a file by the ID.

AllLet me know what you need to do is add the default string, sql text, and IDthink of this. After thatI'm not sure if it's really anything someone could use, you can do the normal event stuff for user-friendly environmentbut it's been very useful to me.

I've taken the base System.Windows.Forms.TextBox and have modified it a little to help me out in creating forms that generate SQL statements. I use to create a large function that would check for changes in the TextBox compared to a string. Then it would take that changed string and concatenate it to a SQL statement. Now it's simple and easier to use. I added two text properties that hold the SQL statement that the text is associated with and the default text displayed. I also added an ID integer for and needs to compare the IDs of textboxes and a boolean to check if the text was modified from the default string.

All you need to do is add the default string, sql text, and ID. After that, you can do the normal event stuff for user-friendly environment.

I've Inherited System.Windows.Forms.TextBox and added a few properties to help me out in creating forms that generate SQL statements. 

I use to create a large function that would check for changes in the TextBox compared to a string. Then it would take text and concatenate it to a SQL statement. Now it's simple and easier to use.

I've added four properties:

  • A String property to hold the default string that the textbox is initially set to and will reset back if the text is left empty.
  • A String property to hold the text's associated SQL statement.
  • A Boolean to check if the text has changed from the default.
  • Finally, an Integer to hold an ID if there is a reason to need one, such as saving and loading text from a file by the ID.

Let me know what you think of this. I'm not sure if it's really anything someone could use, but it's been very useful to me.

edited title
Link
CodeMonkey
  • 451
  • 1
  • 4
  • 12
Loading
Source Link
CodeMonkey
  • 451
  • 1
  • 4
  • 12
Loading