Click here to Skip to main content
16,005,316 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionToggling ON/OFF VB6 reference library in Visual Studio Pin
juno10131-Aug-12 6:27
juno10131-Aug-12 6:27 
AnswerRe: Toggling ON/OFF VB6 reference library in Visual Studio Pin
Dave Kreskowiak31-Aug-12 7:26
mveDave Kreskowiak31-Aug-12 7:26 
GeneralRe: Toggling ON/OFF VB6 reference library in Visual Studio Pin
juno10131-Aug-12 9:06
juno10131-Aug-12 9:06 
GeneralRe: Toggling ON/OFF VB6 reference library in Visual Studio Pin
Dave Kreskowiak31-Aug-12 9:26
mveDave Kreskowiak31-Aug-12 9:26 
GeneralRe: Toggling ON/OFF VB6 reference library in Visual Studio Pin
juno1011-Sep-12 17:49
juno1011-Sep-12 17:49 
GeneralRe: Toggling ON/OFF VB6 reference library in Visual Studio Pin
Dave Kreskowiak1-Sep-12 18:42
mveDave Kreskowiak1-Sep-12 18:42 
QuestionHow to insert an ID number to another table column Pin
garyu8730-Aug-12 20:56
garyu8730-Aug-12 20:56 
AnswerRe: How to insert an ID number to another table column Pin
Wayne Gaylard30-Aug-12 22:24
professionalWayne Gaylard30-Aug-12 22:24 
I see several things here that you are doing wrong. First off, you should not be concatenating strings to create your sql query, rather use Parameterised queries. Second you should use the ADO.Net Transaction to update more than one table at a time. Third, you should use the
SQL
SELECT @@IDENTITY
to return the id of the last inserted row. Here is a quick example of how I would do this :-
using(SqlConnection con = new SqlConnection("yourConnectionString"))
{
    con.Open();
    SqlTransaction trans = con.BeginTransaction();
    try
    {
    	SqlCommand cmdFandB = new SqlCommand("INSERT INTO F&B (breakfast, lunch, dinner) VALUES (@breakfast, @lunch, @dinner);SELECT @@IDENTITY;", con);
    	cmdFandB.Parameters.AddWithValue("@breakfast", txtBreakfast.Text);
    	cmdFandB.Parameters.AddWithValue("@lunch", txtLunch.Text);
    	cmdFandB.Parameters.AddWithValue("@dinner", txtDinner.Text);
    	cmdFandB.Transaction = trans;
    	int FandBID = (int)cmdFandB.ExecuteScalar();
    	SqlCommand cmdExpenses = new SqlCommand("expenses insert query here", con);
    	cmdExpenses.Parameters.AddWithValue("@foodandbeverageid", FandBID);
    	//add other parameters here from text boxes
        cmdExpenses.Transaction = trans;
    	cmdExpenses.ExecuteNonQuery();
    	trans.Commit();
    	MessageBox.Show("Success");
    }
    catch (SqlException sex)
    {
    	trans.Rollback();
    	MessageBox.Show("Failure" + sex.Message);
    }
}


Hope this helps

[Edit]Sorry, example is in C#, but you should get the drift[/Edit]
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman


modified 31-Aug-12 4:44am.

GeneralRe: How to insert an ID number to another table column Pin
garyu8730-Aug-12 23:09
garyu8730-Aug-12 23:09 
GeneralRe: How to insert an ID number to another table column Pin
Wayne Gaylard30-Aug-12 23:19
professionalWayne Gaylard30-Aug-12 23:19 
GeneralRe: How to insert an ID number to another table column Pin
Simon_Whale30-Aug-12 23:20
Simon_Whale30-Aug-12 23:20 
GeneralRe: How to insert an ID number to another table column Pin
garyu8731-Aug-12 0:12
garyu8731-Aug-12 0:12 
GeneralRe: How to insert an ID number to another table column Pin
Wayne Gaylard31-Aug-12 0:19
professionalWayne Gaylard31-Aug-12 0:19 
GeneralRe: How to insert an ID number to another table column Pin
garyu871-Sep-12 20:22
garyu871-Sep-12 20:22 
QuestionRemove controls from a form using For Each Pin
Steven St. John30-Aug-12 5:30
Steven St. John30-Aug-12 5:30 
AnswerRe: Remove controls from a form using For Each Pin
ChandraRam30-Aug-12 8:03
ChandraRam30-Aug-12 8:03 
GeneralRe: Remove controls from a form using For Each Pin
Steven St. John30-Aug-12 12:23
Steven St. John30-Aug-12 12:23 
AnswerRe: Remove controls from a form using For Each Pin
kureigu maikeru31-Aug-12 2:33
kureigu maikeru31-Aug-12 2:33 
GeneralRe: Remove controls from a form using For Each Pin
Steven St. John31-Aug-12 4:15
Steven St. John31-Aug-12 4:15 
GeneralRe: Remove controls from a form using For Each Pin
Simon_Whale31-Aug-12 4:43
Simon_Whale31-Aug-12 4:43 
GeneralRe: Remove controls from a form using For Each Pin
ChandraRam31-Aug-12 8:18
ChandraRam31-Aug-12 8:18 
GeneralRe: Remove controls from a form using For Each Pin
Simon_Whale31-Aug-12 9:04
Simon_Whale31-Aug-12 9:04 
GeneralRe: Remove controls from a form using For Each Pin
Steven St. John1-Sep-12 3:52
Steven St. John1-Sep-12 3:52 
QuestionWPF: delete item per Drag&Drop Pin
Christopher James Kleinheinz29-Aug-12 21:07
Christopher James Kleinheinz29-Aug-12 21:07 
AnswerRe: WPF: delete item per Drag&Drop Pin
Eddy Vluggen30-Aug-12 3:25
professionalEddy Vluggen30-Aug-12 3:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.