This is very simple but something I can never remember how to do!
'So we have a TABLE of data and want to put a title and value into a dropdown on our page.
For row As Integer = 0 To DT.Rows.Count - 1
If Not DT.Rows(row).Item("Title") Is DBNull.Value And Not DT.Rows(row).Item("ID") Is DBNull.Value Then
Dim a As New ListItem
a.Value = districtDT.Rows(row).Item("Title")
a.Text = districtDT.Rows(row2).Item("ID")
myDropDown.Items.Add(a)
End If
Next
There you go!
t
Hey guys,
I would like to find a group of guys that want to post about their particular language.
Most of my stuff is very basic and it really more of a repository for myself so I do not have to keep googling the same stuff over and over again.
IF YOU WOULD like to post on this site or even share links, please email me at ToddVance@Gmail.com.
Thanks!
Below is an example of how to grab all your table names from your database:
*YOU WILL NEED TO IMPORT System.Data.SqlClient for this code.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Create a table to hold the table names
Dim tables As DataTable = New DataTable("Tables")
'Create your connection string and include it in your connection
Using sqlConn As New SqlConnection(constring)
sqlConn.Open()
'This is the sql statement that will bring back your table names
Dim sql As String = "select table_name as Name from INFORMATION_SCHEMA.Tables where TABLE_TYPE = 'BASE TABLE'"
'Command to get the names
cmd = New SqlCommand(sql, sqlConn)
adapter = New SqlDataAdapter(cmd)
'THIS FILLS YOUR TABLE WITH THE TABLE NAMES!
adapter.Fill(tables)
'AT THIS POINT you will have a data table that is filled your table names from your database.
End Using
End Sub
Cheers!
t
o I wanted to pull a random name from my database — I had a bunch of embedded images that matched those names…
My intention was to pull a random name and then fill a pictureBox with that random named embedded image but I could not figure out how to call My.Resource.(???)
Here is how I did it:
Dim resObj As Object = My.Resources.ResourceManager.GetObject(RANDOMNAME)
PictureBox1.Image = CType(resObj, Image)
Created by Dr. Frank McCown, Harding University Computer Science Dept. http://www.harding.edu/fmccown/vbnet_csharp_comparison.html
Program Structure
|
|
| Imports System
Namespace Hello
Class HelloWorld
Overloads Shared Sub Main(ByVal args() As String)
Dim name As String = “VB.NET”
If args.Length = 1 Then name = args(0)
Console.WriteLine(”Hello, ” & name & “!”)
End Sub
End Class
End Namespace |
using System;
namespace Hello {
public class HelloWorld {
public static void Main(string[] args) {
string name = “C#”;
if (args.Length == 1)
name = args[0];
Console.WriteLine(”Hello, ” + name + “!”);
}
}
} |
Data Types
|
|
Boolean
Byte, SByte
Char
Short, UShort, Integer, UInteger, Long, ULong
Single, Double
Decimal
Date
Object
String
Dim correct As Boolean = True
Dim b As Byte = &H2A
Dim o As Byte = &O52
Dim person As Object = Nothing
Dim name As String = “Dwight”
Dim grade As Char = “B”c
Dim today As Date = #12/31/2007 12:15:00 PM#
Dim amount As Decimal = 35.99@
Dim gpa As Single = 2.9!
Dim pi As Double = 3.14159265
Dim lTotal As Long = 123456L
Dim sTotal As Short = 123S
Dim usTotal As UShort = 123US
Dim uiTotal As UInteger = 123UI
Dim ulTotal As ULong = 123UL
Dim x As Integer
Console.WriteLine(x.GetType())
Console.WriteLine(GetType(Integer))
Console.WriteLine(TypeName(x))
Dim d As Single = 3.5
Dim i As Integer = CType(d, Integer)
i = CInt(d)
i = Int(d)
|
bool
byte, sbyte
char
short, ushort, int, uint, long, ulong
float, double
decimal
DateTime
object
string
bool correct = true;
byte b = 0×2A;
object person = null;
string name = “Dwight”;
char grade = ‘B’;
DateTime today = DateTime.Parse(”12/31/2007 12:15:00″);
decimal amount = 35.99m;
float gpa = 2.9f;
double pi = 3.14159265;
long lTotal = 123456L;
short sTotal = 123;
ushort usTotal = 123;
uint uiTotal = 123;
ulong ulTotal = 123;
int x;
Console.WriteLine(x.GetType());
Console.WriteLine(typeof(int));
Console.WriteLine(x.GetType().Name);
float d = 3.5f;
int i = (int)d;
|
Properties
|
|
| Private _size As Integer
Public Property Size() As Integer
Get
Return _size
End Get
Set (ByVal Value As Integer)
If Value < 0 Then
_size = 0
Else
_size = Value
End If
End Set
End Property
foo.Size += 1 |
private int _size;
public int Size {
get {
return _size;
}
set {
if (value < 0)
_size = 0;
else
_size = value;
}
}
foo.Size++; |
File I/O
|
|
| Imports System.IO
Dim writer As StreamWriter = File.CreateText(”c:\myfile.txt”)
writer.WriteLine(”Out to file.”)
writer.Close()
Dim reader As StreamReader = File.OpenText(”c:\myfile.txt”)
Dim line As String = reader.ReadLine()
While Not line Is Nothing
Console.WriteLine(line)
line = reader.ReadLine()
End While
reader.Close()
Dim str As String = “Text data”
Dim num As Integer = 123
Dim binWriter As New BinaryWriter(File.OpenWrite(”c:\myfile.dat”))
binWriter.Write(str)
binWriter.Write(num)
binWriter.Close()
Dim binReader As New BinaryReader(File.OpenRead(”c:\myfile.dat”))
str = binReader.ReadString()
num = binReader.ReadInt32()
binReader.Close()
|
using System.IO;
StreamWriter writer = File.CreateText(”c:\\myfile.txt”);
writer.WriteLine(”Out to file.”);
writer.Close();
StreamReader reader = File.OpenText(”c:\\myfile.txt”);
string line = reader.ReadLine();
while (line != null) {
Console.WriteLine(line);
line = reader.ReadLine();
}
reader.Close();
string str = “Text data”;
int num = 123;
BinaryWriter binWriter = new BinaryWriter(File.OpenWrite(”c:\\myfile.dat”));
binWriter.Write(str);
binWriter.Write(num);
binWriter.Close();
BinaryReader binReader = new BinaryReader(File.OpenRead(”c:\\myfile.dat”));
str = binReader.ReadString();
num = binReader.ReadInt32();
binReader.Close();
|
IE8 has issues with many pages and it’s formatting.
So if you want IE8 to look like IE7 you can embed a meta tag in your pages.
What I have found is that the meta tag needs to be right under the <title> tag in your head before anything else.
Here’s the tag : <meta http-equiv=”X-UA-Compatible” content=”IE=EmulateIE7″ />
Hope this helps!
:even Selects every other (even) element from the matched element set.
:odd Selects every other (odd) element from the matched element set.
:eq(0) and :nth(0) Selects the Nth element from the matched element set
:gt(N) Selects all matched elements whose index is greater than N.
:lt(N) Selects all matched elements whose index is less than N.
:first Equivalent to :eq(0)
:last Selects the last matched element.
:parent Selects all elements which have child elements (including text).
:contains(’test’) Selects all elements which contain the specified text.
:visible Selects all visible elements (this includes items that have a display of block or inline, a visibility of visible, and aren’t form elements of type hidden)
:hidden Selects all hidden elements (this includes items that have a display of none, or a visibility of hidden, or are form elements of type hidden)
So working with a custom control and having trouble manipulating a couple input boxes in that control on the page that the control lives in.
So I had a custom control embedded on a page with two calendar input boxes. I wanted to check on the submit button to that the end date was after the start date. I could not get this to work in the control.
But I was able to give those text boxes class names (ie: cssClass=”DatesTB”) and on the page that the control resided in I simply did this on the submit button click (in html) ….
if ($("input.DatesTB:first").val() > $("input.DatesTB:last").val()) {
writeMessageToPage("The End Date must be after the Start Date.");
return false;
}
Notice how you can cooly grab the FIRST input box with a specific class name by the JQuery selector
$(”input.CLASSNAME:first) and subsequently get the last one with the “last” identifier!
Very nice and very helpful JQUERY! I love you!!!!
You can also do something like this $(”td:eq(2)”) to get a certain number of element on your page.
That example would be grabbing the 3rd TD on the page.
Love it, hope it helps!
This could be good for storing gathered data from your users and retaining it.
1. Go to your Projects property page by clicking ‘Project’ and the ‘Properties’.
2. From here click ‘Resources’, ‘Add Resource’, and then ‘Add new Text File’
3. Now back to your code behind you simply reference your text file as such:
Dim username As String = TextBox1.Text
Dim password As String = TextBox2.Text
sw = New StreamWriter("My.Resources.Users", True)
sw.WriteLine(username & password)
sw.Close()
Notice the “My.Resources.Users” — Users.txt is what I named my text file so replace that name with your text file name.
Now you can write data to a simple text file (OBVIOUSLY) you would not want to store sensitive data in this BUT it does get compiled into the project so you will never need to worry about the package being installed in the wrong place. This text file will ALWAYS be with this program! Very nice…..
I read from the file like this :
sr = New StreamReader("My.Resources.Users")
Dim line As String
Do
line = sr.ReadLine
Loop Until line Is Nothing
sr.Close()
Cheers and caio!