Mitja Bonca 557 Nearly a Posting Maven
Mitja Bonca 557 Nearly a Posting Maven
johnt68 commented: Big thankyou +2
TheBadger commented: Thx that works great! +1
Np :)
Remove brackets:
string All = "aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ0123456789`~!@#$%^&*()_-=+[]{};:'|/?.>,<";
and the for the All you have to assign index with [] brackers:
Password = Password + All[rdmNumber];
try this out:
class Program
{
static void Main(string[] args)
{
Program p = new Program();
//p.InsertDoc();
//p.RetriveDoc();
Console.Read();
}
public void InsertDoc()
{
byte[] doc = GetDocFromHDD(@"C:\Users\Radwan\Documents\Test.doc");
OleDbConnection Conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; User Id=;Data Source=C:\\Users\\Radwan\\Documents\\Database1.mdb");
OleDbCommand addDoc = new OleDbCommand("insert into table1 (data,fileLength) values(@doc,@length)", Conn);
OleDbDataAdapter MyDataAdapter = new OleDbDataAdapter();
MyDataAdapter.InsertCommand = addDoc;
OleDbParameter docPar = new OleDbParameter("@data", OleDbType.VarBinary, doc.Length);
docPar.Value = doc;
OleDbParameter length = new OleDbParameter("@length", OleDbType.Integer);
length.Value = doc.Length;
MyDataAdapter.InsertCommand.Parameters.Add(docPar);
MyDataAdapter.InsertCommand.Parameters.Add(length);
// connect
Conn.Open();
// insert
addDoc.ExecuteNonQuery();
Conn.Close();
//........
}
public void RetriveDoc()
{
//byte[] doc = GetDoc(@"C:\Users\Radwan\Documents\Test.doc");
OleDbConnection Conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; User Id=;Data Source=C:\\Users\\Radwan\\Documents\\Database1.mdb");
OleDbCommand selectDoc = new OleDbCommand("select data,FileLength from table1 where id = @id", Conn);
OleDbDataAdapter MyDataAdapter = new OleDbDataAdapter();
MyDataAdapter.SelectCommand = selectDoc;
OleDbParameter id = new OleDbParameter("@id", OleDbType.Integer);
id.Value = 1;
MyDataAdapter.SelectCommand.Parameters.Add(id);
// connect
Conn.Open();
// insert
OleDbDataReader reader = selectDoc.ExecuteReader();
byte[] buffer = null;
while (reader.Read())
{
int docLength = reader.GetInt32(1);
buffer = new byte[docLength];
reader.GetBytes(0, 0, buffer, 0, docLength);
string s = reader.GetDataTypeName(0);
//reader.
}
Conn.Close();
SaveDocToHDD(buffer);
//........
}
private void SaveDocToHDD(byte[] buffer)
{
FileStream fs = new FileStream(@"C:\Users\Radwan\Documents\Output.doc", FileMode.Create, FileAccess.ReadWrite);
BinaryWriter bw = new BinaryWriter(fs);
bw.Write(buffer);
}
private byte[] GetDocFromHDD(string p)
{
FileStream fs = new FileStream(p, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
return br.ReadBytes((int)fs.Length);
}
}
Change to:
enum PasswordScore
{
Blank = 0,
VeryWeak = 1,
Weak = 2,
Medium = 3,
Strong = 4,
VeryStrong = 5
}
private static PasswordScore CheckingPasswordStrength(string password)
{
int score = 1;
if (password.Length < 1)
return PasswordScore.Blank;
if (password.Length < 4)
return PasswordScore.VeryWeak;
if (password.Length >= 8)
score++;
if (password.Length >= 12)
score++;
if (Regex.IsMatch(password, @"[0-9]+(\.[0-9][0-9]?)?", RegexOptions.ECMAScript)) //number only //"^\d+$" if you need to match more than one digit.
score++;
if (Regex.IsMatch(password, @"^(?=.*[a-z])(?=.*[A-Z]).+$", RegexOptions.ECMAScript)) //both, lower and upper case
score++;
if (Regex.IsMatch(password, @"[!,@,#,$,%,^,&,*,?,_,~,-,L,(,)]", RegexOptions.ECMAScript)) //^[A-Z]+$
score++;
return (PasswordScore)score;
}
Here is one simple example:
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream ;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*" ;
saveFileDialog1.FilterIndex = 2 ;
saveFileDialog1.RestoreDirectory = true ;
if(saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if((myStream = saveFileDialog1.OpenFile()) != null)
{
// Code to write the stream goes here.
myStream.Close();
}
}
}
You better try it, you will see it works.
btw, can I see your code?
Would you show in this code where is the problem? From that Icannot see what it could be.
You ae constantly chnaging methods on comboBox. Ones you select SelectedValue, next time you select SelectedText, and another time you select SelectedItem method.
Do you know the difference between them?
I bet you do not know, thats why you have problems.
Let me explain in general:
1. Combobox can have 2 different type of data in one row (item and value).
If you have a custom class:
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
List<Person> list = new List<Person>();
list.Add(new Person { ID = 1, Name = "Some name" });
list.Add(new Person { ID = 2, Name = "Other one" });
//now you can assing item and a value to comboBox (and before you have to bind the list to it):
comboBox1.DataSource = list;
comboBox1.DisplayMember = "Name";
comboBox1.ValueMember = "Id";
}
//Ok, lets move on...
//When you want to get the item and the value (Name and ID) on comboBox selection you can do:
private void button1_Click(object sender, EventArgs e)
{
int _id = int.Parse(comboBox1.SelectedValue.ToString());
string _name1 = comboBox1.Text;
//or with a Person`s class help:
string _name2 = (comboBox1.SelectedItem as Person).Name;
MessageBox.Show(String.Format("Selected person is {0}, with ID {1}.", _name2, _id));
}
}
class Person
{
public int ID { get; set; }
public string Name { get; set; }
}
Do you see now what is the Value and what is …
To get the path toapplication you can try on of these:
Dim Path1 As String = Application.StartupPath
Dim exe As System.Reflection.Assembly = System.Reflection.Assembly.GetEntryAssembly()
Dim Path2 As String = System.IO.Path.GetDirectoryName(exe.Location)
Dim Path3 As String = Path.GetDirectoryName(Application.ExecutablePath)
Dim path4 As String = Path.GetDirectoryName(Assembly.GetAssembly(GetType(Form1)).CodeBase)
Dim strAppDir As [String] = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
Dim strFullPathToMyFile As [String] = Path.Combine(strAppDir, "fileName.txt")
Dim root As String = New FileInfo(Assembly.GetExecutingAssembly().Location).FullName
Dim fullAppName As [String] = Assembly.GetExecutingAssembly().GetName().CodeBase
Dim fullAppPath As [String] = Path.GetDirectoryName(fullAppName)
Dim fullFileName As [String] = Path.Combine(fullAppPath, "myfile.txt")
You can do it more appropriate with creating its own method, and call it from your main one:
Private Sub MyMethod()
Dim toCheck As String = "someValue"
Dim bChecking As Boolean = Checking(textBox1.Text, toCheck)
If bChecking Then
MessageBox.Show("Values are equal.")
Else
MessageBox.Show("Values are different.")
End If
End Sub
Private Shared Function Checking(input As String, toCheck As String) As Boolean
Return If(input.Equals(toCheck), True, False)
End Function
have you checked my solution?
just after you populate the comboBox, call this property:
comboBox1.SelectedIndex = -1;
This way the by default will nothing be selected.
But this will only work if you populate comboBox manually; that means that the comboBox is not data bound.
I didnt really get you what do you want.
If I understand you correctly, when you get your data from the "some where" (DB), you populate comboBox and do the automatic selection. And your problem is that when you do it, there nothing gets selected. Am I right?
BTW: would be in a much help, if you would show us some code, instead of just talking here.
thx in advance,
How do I figure out about dynamic each of tabs in GUI with C#?
Ok, But what would you like to know? Pleaseee... tell us some more...
Can you do that?
Simple :)
You will have to use a Timer object to update the time in the DGV`s headerText:
System.Windows.Forms.Timer timer1;
public Form1()
{
InitializeComponent();
dataGridView1.Columns.Add("col1", "");
dataGridView1.Columns.Add("col2", "Column 2");
dataGridView1.Columns[0].HeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleCenter;
ShowTime();
timer1 = new Timer();
timer1.Interval = 1000;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
ShowTime();
}
private void ShowTime()
{
string time = String.Format("{0:HH:mm:ss}", DateTime.Now);
dataGridView1.Columns[0].HeaderText = time;
}
You can simple use a StreamWriter object in the else block
using (StreamWriter sw = File.AppendText(@"C:\1\log_1.txt"))
{
sw.WriteLine(value);
}
What do you mean? Can you explain your issue a bit better? And about which Tabs are you talking about? Of TabControl control?
You want that the ColumnHeader of one column in the DGV shows the time? and the time in thr real time?
np mate
Iam glad you like it,
and I wrote the code by heart ;)
This one?
string[] sArray = {"a", "b", "b", "c", "c", "d", "e", "f", "f"};
var sList = new ArrayList();
for (int i = 0; i < sArray.Length; i++) {
if (sList.Contains(sArray[i]) == false) {
sList.Add(sArray[i]);
}
}
var sNew = sList.ToArray();
for (int i = 0; i < sNew.Length; i++) {
Console.Write(sNew[i]);
}
BTW: if you want to get the text one beside another - in one line, you only have to change StringBuilder`s AppendLine() method with only Append().
Simple
Enjoy :)
First you have to create a global TextBox variable array, so in the whole class is visible. Then create textboxes, and when you need to loop through them, do the following (code at the bottom):
TextBox[] tbs;
void CreatingTextboxes()
{
tbs = new TextBox[int.Parse(numericUpDown.Value)];
//now loop with your code from the top and create textBoxes in the a bit different way they you did:
int x = 20;
int y = 30;
for(int i = 0; i< tbs.Lenght; i++)
{
tbs[i] = new TextBox();
tbs[i].Name = "textBox" + i+1;
tbs[i].Location = new Point (x, y);
tbs[i].Width = 100;
this.Controls.Add(tbs[i]);
//set new coordinated for a new textbox:
y += 30; //vertical
x += 0; //horizontal - do what ever you want to put them in the form!
}
}
void GetTextFromTextBoxes()
{
StringBuilder sb = new StringBuilder();
foreach(Control c in this.Controls)
{
if(c is TextBox && c != null)
{
Textbox tb = c as TextBox;
//read each text from textBox:
if(tb.Text != String.Empty)
sb.AppendLine(tb.Text);
}
}
//lets show the text in all textBoxes!
MessageBox.Show(sb.ToString());
//you can do with the text what ever you want, I only wanted to show how to get all the text from each textBox on the form, and get them together trom all of them!
}
Let me know what do you think,
bye,
Check out this code to remove duplicates:
int[] s = { 1, 2, 3, 3, 4};
int[] q = s.Distinct().ToArray();
1st think that I have to mention here (and I forgot to say it before), you have to get the last ID from the dataBase, so you can continue inserting from then on.
you can use a "SELECT MAX(IDCOumnNAME) FROM myTable" statement. The you can do:
Dim product As String() = New String(9) {}
product(0) = strProductIDselected1
product(1) = strProductIDselected2
product(2) = strProductIDselected3
product(3) = strProductIDselected4
product(4) = strProductIDselected5
product(5) = strProductIDselected6
product(6) = strProductIDselected7
product(7) = strProductIDselected8
product(8) = strProductIDselected9
product(9) = strProductIDselected10
'GET THE LATEST ID!!
'IF THERE IS NONE( (empty table) SET IT TO 0
'AND DO INCREMENTATION: Add +1 - to get a new ID!!
For i As Integer = 0 To product.Lenght - 1
If intTest > 0 Then
' intMaxOrderID is ALWAYS THE Same - and thats why you will get an error,
'becuase you cannot have 2 identical ids in the dataBase`s table!!
'and even the strTest is always the same!!
'I have no clue how you will get new values, and I dont even know why this loop is all about!
Dim strSQLCommand3 As String = "INSERT INTO OrderLine(OrderID, ProductID) VALUES ('" & intMaxOrderID & "', '" & product(i) & "')"
Dim objOleDbCommand3 As New System.Data.OleDb.OleDbCommand(strSQLCommand3, objOleDbConnection)
objOleDbCommand3.ExecuteNonQuery()
'you can create a new ID with simple add +1:
'if you want to create a new id in the dataTable!!
intMaxOrderID += 1
End If
Next
objOleDbConnection.Close()
for(int i = 0; i< listBox1.Items.Count; i++)
{
if(listBox1.Items[i] == textBox1.Text)
{
//item found
break;
}
}
If you want to do a Math operations over some data, these data have to be a true numbers. You cannot do math operations over strings (like the text property provides of the textBox).
You can do:
int value1 = int.Parse(textBox1.Text);
int value 2 = int.Parse(textBox2.Text);
//put a result into 3rd textBox:
textBox3.Text = (value1 * value2).Tostring();
Hope this clears on which kind of data you can do math operations, and on which you cannot. You can do on all number types, like int, decimal, floaf, double,...
If I look into your string query (INSERT INTO...) you always through the loop insert the same values. I thnik this is not the point here, or am I wrong?
Anyway, you can do the loop something like this, but you will have to get new values for ID and strTest value somehow:
Dim intICount As Integer
Dim strTest As String = Nothing
strTest = "intProductIDSelected" & intICount
objOleDbConnection.Open()
For intICount = 0 To 8
If intTest > 0 Then
' intMaxOrderID is ALWAYS THE Same - and thats why you will get an error,
'becuase you cannot have 2 identical ids in the dataBase`s table!!
'and even the strTest is always the same!!
'I have no clue how you will get new values, and I dont even know why this loop is all about!
Dim strSQLCommand3 As String = "INSERT INTO OrderLine(OrderID, ProductID)" & "VALUES ('" & intMaxOrderID & "', '" & strTest & "')"
Dim objOleDbCommand3 As New System.Data.OleDb.OleDbCommand(strSQLCommand3, objOleDbConnection)
objOleDbCommand3.ExecuteNonQuery()
'you can create a new ID with simple add +1:
'if you want to create a new id in the dataTable!!
intMaxOrderID += 1
End If
Next
objOleDbConnection.Close()
You can even try it this way:
Dim sb As New StringBuilder()
For i As Integer = 0 To listView1.Items.Count - 1
sb.AppendLine()
For j As Integer = 0 To listView1.Columns.Count - 1
sb.Append(listView1.Items(i).SubItems(j).Text)
If (i + 1) < listView1.Items.Count OrElse (j + 1) < listView1.Columns.Count Then
sb.Append(",")
End If
Next
Next
Using sw As New System.IO.StreamWriter("C:\1\CSV_test.csv")
sw.Write(sb.ToString())
End Using
Anyway, here is my code of putting dgv`s content to a csv file:
Private Sub buttonSave_Click(sender As Object, e As EventArgs)
Dim sbCSV As New StringBuilder()
Dim intColCount As Integer = dt.Columns.Count
For Each dr As DataRowView In dt.DefaultView
For x As Integer = 0 To intColCount - 1
sbCSV.Append(dr(x).ToString())
If (x + 1) <> intColCount Then
sbCSV.Append(",")
End If
Next
sbCSV.Append(vbLf)
Next
Using sw As New StreamWriter("c:\csv\table1.csv")
sw.Write(sbCSV.ToString())
End Using
End Sub
Try to remove "Value" from the if statement:
If dc IsNot Nothing Then
strExport += dc.Value.ToString() & " "
End If
Try splitting it(as said in the post abouve with th Split method.
And do it like:
while (reader.Read())
{
string[] array = reader[0].ToString().Split(',');
foreach (string item in array)
lstPK.Items.Add(item);
}
Even if there will be no comma in the string, there will always be one item to add to listBox.
:) just something that is simple, right?
int rowsCount = cmd.ExecuteNonQuery();
You mean to get all values from all columns and add them into one cell?
Into same dataGridView or into some other one?
Hi,
what allignment is concerned, I would strongy suggest to use some other control like listView, or dataGridView.
What do you think?
YOu can still edit data there.
You mean this code:
private void cmbProgramme_SelectedIndexChanged(object sender, EventArgs e)
{
//DO NOT USE THIS NOW ANY MORE!!
cmbCourses.Items.Clear(); //you say this is not working??
// And the rest
This has to work, especially becuase you ADD items to comboBox - your comboBox is not dataBound!!
... but
Lets change the code a bit to:
SqlCommand cmd = new SqlCommand(@"SELECT C_Name FROM tblCourses WHERE P_Name = '" + cmbProgramme.SelectedItem.ToString() + "'", MyConnection);
MyDataAdapter = new SqlDataAdapter(cmd);
//You dont need to fill comboBox item by item, you can set the it`s dataSouce to the dataTable:
cmbCourses.DataSource = table;
cmbCourses.DispayValue = "C_Name";
cmbCourses.ValueMember= cmbCourses.DisplayMember;
//nothing else!
//AND BTW: if you use DataSource property - you have to remove the line of comboBox.Items.Clear() method !
Check it out, and let me know if it works...
cmbCourses.Items.Clear();
method should clear all the items from comboBox. if not try with additional code ( both):
cmbCourses.SelectedIndex = -1;
In your method "ADdFileToListViewSRT" you have to change the code of Items[xx] - where xx is i!
//in the for loop:
listView1.Items[i].SubItems[2].Text = fileName;
//do the same for all 3 (change with the i variable).
Check this out:
But be careful with the column number (as far as I can see you assign date value to 14th subitem - mine is on 2nd (Subitems[1]):
Public Sub New()
InitializeComponent()
listView1.Columns.Add("Id", 50, HorizontalAlignment.Left)
listView1.Columns.Add("Date and time", -2, HorizontalAlignment.Left)
listView1.View = View.Details
listView1.FullRowSelect = True
'add example data:
Dim table As New DataTable("MyTable")
table.Columns.Add("Id", GetType(Integer))
table.Columns.Add("Date", GetType(DateTime))
table.Rows.Add(1, DateTime.Today.AddDays(-1))
table.Rows.Add(2, DateTime.Today)
'put this data to listView:
For Each dr As DataRow In table.Rows
Dim lvi As New ListViewItem()
lvi.Text = dr(0).ToString()
lvi.SubItems.Add([String].Format("{0:MM/dd/yyyy hh:mm:ss}", Convert.ToDateTime(dr(1))))
listView1.Items.Add(lvi)
Next
'create a listView event:
listView1.SelectedIndexChanged += New EventHandler(AddressOf listView1_SelectedIndexChanged)
End Sub
Private Sub listView1_SelectedIndexChanged(sender As Object, e As EventArgs)
If listView1.SelectedIndices.Count > 0 Then
Dim value As String = listView1.SelectedItems(0).SubItems(1).Text
If value IsNot Nothing Then
dateTimePicker1.Value = Convert.ToDateTime(value)
End If
End If
End Sub
I dont really get yout question. Is it that you cant retreive the stirng of the subitem (the path of the subtitle)?
To get subitem you do:
string path = listView.SelectedItems[0].SubItems[1].Text;
You can have (use) only one connection through all the code, and ONLY one connection string.
It would be even better to create connection string as global (too seeable in the whole class and static):
Take into yours changed code:
static string connString = "SERVER=44.6.53.34;User=sa;password=56fgq3546fd5qFDGF;Database=addressstagingtable";
private void xmlBTN_Click(object sender, EventArgs e)
{
using (SqlConnection sqlConn = new SqlConnection(connString))
{
sqlConn.Open();
string sqlQuery6 = @"Update Lalocation Set State = @State where state = 'XX'";
SqlCommand cmd6 = new SqlCommand(sqlQuery6, sqlConn);
cmd6.Parameters.Add("@State", SqlDbType.NVarChar, 2).Value = statetxt.Text;
try
{
cmd6.ExecuteNonQuery();
}
catch (Exception)
{
MessageBox.Show("Table: LALOCATION FIELD: State did not update, please contact your C.A.R.T.S System Administrator", "MPL");
}
string sqlQuery7 = @"Update Lalocation Set zip = @Zip WHERE Zip = 'XXXXX'";
SqlCommand cmd7 = new SqlCommand(sqlQuery7, sqlConn);
cmd7.Parameters.Add("@Zip", SqlDbType.NVarChar, 2).Value = ziptxt.Text;
try
{
cmd7.ExecuteNonQuery();
}
catch (Exception)
{
MessageBox.Show("Table: LALOCATION FIELD: State did not update, please contact your C.A.R.T.S System Administrator", "MPL");
}
}
}
Hi,
it hard to tell what could be done better. There is to much to learn. This code looks ok, and it works, but I dont know exaclty what do you want to do with it.
On the button click event 1st delete all what you want (textBox content), and then populate it again. Simple.
I should work. Take a look at this simple example:
class MyClass
{
string a; //this will not be initialized, but there will be no error in compile time
string b = "b";
public void MyMethod()
{
a = "a";
string c; //this will not be initialized, but there will be no error in compile time
string d = "d";
}
}
This all works.
Hi,
one thing: a "list" as you have stated - it canNOT have checkBoxes at all. It can only contain some boolean values.
So, in your code you have a generic list<T> with a custom class "filterHistory". This is a class which has a boolan property - for the checkBox checked/uncheced if I`m not wrong.
I hope I`m not wrong - but this is only my presuming, regarding your code, so we can do the following: lets loop through the list, and check for that boolean property - if value is true - delete the data (if false, do notihing; dont delete the data):
for(filterHistory item in histList)
{
if(item.checkUncheck)
{
//here item is true! so you can delete the data!!
}
}
//your filterHistory class //this is only my predistion how it looks:
class filterHistory
{
public bool checkUncheck { get; set; }
//and the rest
}
Just to add:
... be careful here. adatapost is correct, but be careful in two things
- row index
- column index
You have to state the correct indexes, and for the column you can even state the column name!
The code looks fine. Where should be the problem?
Into this code you got the customers with their data:
Customer cust = new Customer();
SortedList custList = cust.ListCustomerByPostcode(ECenterPostcodeTextBox.Text);
//custList hold now customers data!!
//now you want to put them to listBox!
//you will have to loop through the list and add them one by one:
for(int i = 0; i< custList.Count; i++) //instead of count, cound be Lenght property! not sure atm
{
lstCustomerSelect.Items.Add(custList[i]);
}
But it might work even without any loop, just to use AddRange method
lstCustomerSelect.Items.AddRange(custList[i]); //not sure, try it out
I hope i didnt do a lot of mistakes, I wrote this by heart.
:) np
I am glad it does.
Create a get;set; modifier and access to in from both classes.
//main form:
public static intSaldo { get; set; }
//set it on a button click:
intSaldo = int.Parse(textBoxSaldo.Text);
//read it when you want (when comming back to main form):
private void ReadSaldo()
{
int _saldo = intSaldo;
//do with it what ever you want!
//and intSaldo is also available in the whole class - its global variable (and in other classes too!
}
//on form2:
void GetSaldo()
{
//access to saldo on main form:
int saldo = MainForm.intSaldo;
}
If this is not it, please go ahead and ask for more.
Sure it is:
Rabit[] rabits = new Rabit[10];
Fox[] foxes = new Fox[6];
Dog[] dogs = new Dog[4];
for(int i = 0; i < 10;i++)
{
Rabit r = new Rabit();
rabits[i] = r;
if(i < 6)
{
Fox f = new Fox();
foxes[i] = f;
}
if(i < 4)
{
Dog d = new Dog();
dogs[i] = d;
}
}
Now you have 3 arrays of the classes
If you dont want to have classes in the array, simply dont use array, and create classes as abouve:
for(int i = 0; i < 10;i++)
{
Rabit r = new Rabit();
if(i < 6)
Fox f = new Fox();
if(i < 4)
Dog d = new Dog();
}
Just a question: Why do you have this kind of dataBase structure. Correct me if Iam wrong, but this seems not to be correct at all. But anyway, this is not my problem.
This way you will never get the best results. Anyway, you can use my code and re-edit it to suit your needs.
So Row 0 is the cakeName and Row 1 is its Amount!
You can do it:
Dim amount As Integer = 0
If Integer.TryParse(textBox1.Text, amount) Then
Dim cake As String = comboBox1.Text
ds.Tables("CakePie").Rows(1)("YourCakeName") = amount
da.Update(ds, "CakePie")
con.Close()
Exit
Else
MessageBox.Show("Input is not in correct format.")
End If