Click here to Skip to main content
15,906,296 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
AnswerRe: 1.1 and 2.0 on same iis Pin
Gibzon20-Dec-05 21:07
Gibzon20-Dec-05 21:07 
QuestionSuspend or Pause a Process Pin
tboydva17-Dec-05 5:15
tboydva17-Dec-05 5:15 
AnswerRe: Suspend or Pause a Process Pin
Dave Kreskowiak20-Dec-05 5:04
mveDave Kreskowiak20-Dec-05 5:04 
GeneralRe: Suspend or Pause a Process Pin
tboydva21-Dec-05 13:55
tboydva21-Dec-05 13:55 
QuestionRegistry Permissions Pin
Yevgeny Efter16-Dec-05 12:15
Yevgeny Efter16-Dec-05 12:15 
AnswerRe: Registry Permissions Pin
Colin Angus Mackay16-Dec-05 12:44
Colin Angus Mackay16-Dec-05 12:44 
GeneralRe: Registry Permissions Pin
Yevgeny Efter17-Dec-05 2:55
Yevgeny Efter17-Dec-05 2:55 
QuestionNewbie Master Detail Pin
Elvis_Pretzelator16-Dec-05 6:58
Elvis_Pretzelator16-Dec-05 6:58 
This can't be this difficult! I created 2 datagridviews where dg1 displays the parent table and dg2 the child table. Selecting and updating records is not a problem. The problem comes when I try to insert records.

I'm using MySQL 4 and Visual Studio 2005. I write in C#. I'm fairly new to C# and the whole .NET "thing" so I don't know if this is the right board but I figured I'd give it a shot.

If I want to insert a new record, I have to insert the parent record first. Update it. Close the app. Re-launch it. And then I can insert my child records in the recently created parent record. Also, only one new parent record at a time. I know this is ridiculous but it's the only way I can insert to the db.

Any ideas?

MySQL db:

Parent table: tbl_parent
id int(10) not null auto_increment,
name varchar(40),
primary key(id)

Child table: tbl_child
id int(10) not null auto_increment,
ref_id int(10),
name varchar(40),
cost float(4,2),
primary key(id),
foreign key(ref_id) references tbl_parent(id)
on update cascade
on delete cascade



As for my C# code:
**Note: this is just one of many messes I've made!

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Odbc;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MySql
{
public partial class Form1 : Form
{
//
private OdbcConnection cnn;
private OdbcDataAdapter da0;
private OdbcDataAdapter da1;
private BindingSource bsMaster = new BindingSource();
private BindingSource bsDetails = new BindingSource();
private OdbcCommandBuilder cb0;
private OdbcCommandBuilder cb1;
private DataSet ds = new DataSet();
//
public Form1()
{
InitializeComponent();
}

private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}

private void btnConnect_Click(object sender, EventArgs e)
{
this.dg1.DataSource = bsMaster;
this.dg2.DataSource = bsDetails;
this.GetData();
}

private void btnUpdate_Click(object sender, EventArgs e)
{
//not sure which one to use
//DataSet changes = new DataSet();
//changes = ds.GetChanges();
//this.da0.Update(changes, "meal");
//this.da1.Update(changes, "details");
//this.ds.AcceptChanges();
//
this.Validate();
this.bsMaster.EndEdit();
this.da0.Update(ds, "meal");
this.da1.Update(ds, "details");
this.ds.AcceptChanges();
}

private void dg1_CellLeave(object sender, DataGridViewCellEventArgs e)
{

}
private void GetData()
{
string user = txtUser.Text;
string pwd = txtPwd.Text;
string cnnString = @"DRIVER={MySQL ODBC 3.51 Driver};" +
"SERVER=localhost;DATABASE=mydb;" +
"USER=" + user + ";PASSWORD=" + pwd + ";OPTION=3";
if (cnn != null)
cnn.Close();

try
{
this.cnn = new OdbcConnection(cnnString);
this.da0 = new OdbcDataAdapter("select * from tbl_parent order by name", cnn);
this.da1 = new OdbcDataAdapter("select * from tbl_child", cnn);
this.cb0 = new OdbcCommandBuilder(da0);
this.cb1 = new OdbcCommandBuilder(da1);
this.da0.Fill(ds, "main");
this.da1.Fill(ds, "details");
DataRelation rel = ds.Relations.Add("maindetails",
ds.Tables["main"].Columns["id"],
ds.Tables["details"].Columns["ref_id"]);
this.bsMaster.DataSource = ds;
this.bsMaster.DataMember = "main";
this.bsDetails.DataSource = bsMaster;
this.bsDetails.DataMember = "maindetails";
}
catch (OdbcException ex)
{
MessageBox.Show("Error while connecting: " + ex.Message);
}
}


}
}
QuestionWinForm Control in ASP, Framework 2.0 Pin
d_j_w16-Dec-05 5:00
d_j_w16-Dec-05 5:00 
Questionproperty info error Pin
Savas Cilve16-Dec-05 4:09
Savas Cilve16-Dec-05 4:09 
AnswerRe: property info error Pin
Robert Rohde22-Dec-05 10:20
Robert Rohde22-Dec-05 10:20 
QuestionContextMenuStrip and DefaultItem Pin
cual15-Dec-05 7:22
cual15-Dec-05 7:22 
Questionopen forms of an external application? Pin
LordZoster14-Dec-05 11:24
LordZoster14-Dec-05 11:24 
AnswerRe: open forms of an external application? Pin
Dave Kreskowiak14-Dec-05 12:26
mveDave Kreskowiak14-Dec-05 12:26 
GeneralRe: open forms of an external application? Pin
LordZoster14-Dec-05 22:34
LordZoster14-Dec-05 22:34 
AnswerRe: open forms of an external application? Pin
Ingo14-Dec-05 21:36
Ingo14-Dec-05 21:36 
QuestionAssociate File Extension in WinCE 5.0 - CF 1.0 SP2 C# Pin
Marco [Stinger]14-Dec-05 4:55
Marco [Stinger]14-Dec-05 4:55 
AnswerRe: Associate File Extension in WinCE 5.0 - CF 1.0 SP2 C# Pin
Ingo14-Dec-05 21:50
Ingo14-Dec-05 21:50 
QuestionCF 1.0 SP3 - WinCE - FullScreen and Controls.Clear() - Add() Pin
Marco [Stinger]14-Dec-05 2:09
Marco [Stinger]14-Dec-05 2:09 
AnswerRe: CF 1.0 SP3 - WinCE - FullScreen and Controls.Clear() - Add() Pin
Ingo14-Dec-05 3:32
Ingo14-Dec-05 3:32 
GeneralRe: CF 1.0 SP3 - WinCE - FullScreen and Controls.Clear() - Add() Pin
Marco [Stinger]14-Dec-05 4:52
Marco [Stinger]14-Dec-05 4:52 
GeneralRe: CF 1.0 SP3 - WinCE - FullScreen and Controls.Clear() - Add() Pin
Ingo14-Dec-05 21:43
Ingo14-Dec-05 21:43 
QuestionComboBox Pin
Assaf8213-Dec-05 14:24
Assaf8213-Dec-05 14:24 
AnswerRe: ComboBox Pin
Christian Graus13-Dec-05 15:01
protectorChristian Graus13-Dec-05 15:01 
QuestionRegistry search Pin
Yevgeny Efter13-Dec-05 8:57
Yevgeny Efter13-Dec-05 8:57 

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.