Databinding small mistakes
-
Hello, Am trying to bind data.This is my code.Is there any problem with my code since it does not seem to work. Take your time. Thanking You using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace TestDb { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnInsert_Click(object sender, EventArgs e) { OleDbConnection conObj = new OleDbConnection(); conObj.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\j\My Documents\MyDb.mdb"; conObj.Open(); OleDbCommand cmdObj = new OleDbCommand(); cmdObj.CommandText = "Insert into MyTable(Name) values ('" + txtName.Text + "')"; cmdObj.Connection = conObj; cmdObj.ExecuteNonQuery(); txtName.Clear(); } private void btnBind_Click(object sender, EventArgs e) { OleDbConnection conObj = new OleDbConnection(); conObj.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\j\My Documents\MyDb.mdb"; conObj.Open(); OleDbCommand cmdObj = new OleDbCommand(); cmdObj.CommandText = "select Name from MyTable"; DataSet ds = new DataSet(); cmdObj.Connection = conObj; OleDbDataAdapter adapObj = new OleDbDataAdapter(); adapObj.SelectCommand = cmdObj; adapObj.Fill(ds); } } }
-
Hello, Am trying to bind data.This is my code.Is there any problem with my code since it does not seem to work. Take your time. Thanking You using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace TestDb { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnInsert_Click(object sender, EventArgs e) { OleDbConnection conObj = new OleDbConnection(); conObj.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\j\My Documents\MyDb.mdb"; conObj.Open(); OleDbCommand cmdObj = new OleDbCommand(); cmdObj.CommandText = "Insert into MyTable(Name) values ('" + txtName.Text + "')"; cmdObj.Connection = conObj; cmdObj.ExecuteNonQuery(); txtName.Clear(); } private void btnBind_Click(object sender, EventArgs e) { OleDbConnection conObj = new OleDbConnection(); conObj.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\j\My Documents\MyDb.mdb"; conObj.Open(); OleDbCommand cmdObj = new OleDbCommand(); cmdObj.CommandText = "select Name from MyTable"; DataSet ds = new DataSet(); cmdObj.Connection = conObj; OleDbDataAdapter adapObj = new OleDbDataAdapter(); adapObj.SelectCommand = cmdObj; adapObj.Fill(ds); } } }
Trustapple wrote:
Hello, Am trying to bind data.This is my code.Is there any problem with my code since it does not seem to work. Take your time. Thanking You
I didn't look at the code you provided, because you weren't specific. When you say "it doesn't work," you need to be more specific. How does it not work? Does it get errors on build, a run-time exception, or does it just sit there and do nothing? Have you tried setting breakpoints to see what your code is doing?
I'm going to become rich when I create a device that allows me to punch people in the face over the internet. "If an Indian asked a programming question in the forest, would it still be urgent?" - John Simmons / outlaw programmer
-
Hello, Am trying to bind data.This is my code.Is there any problem with my code since it does not seem to work. Take your time. Thanking You using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace TestDb { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnInsert_Click(object sender, EventArgs e) { OleDbConnection conObj = new OleDbConnection(); conObj.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\j\My Documents\MyDb.mdb"; conObj.Open(); OleDbCommand cmdObj = new OleDbCommand(); cmdObj.CommandText = "Insert into MyTable(Name) values ('" + txtName.Text + "')"; cmdObj.Connection = conObj; cmdObj.ExecuteNonQuery(); txtName.Clear(); } private void btnBind_Click(object sender, EventArgs e) { OleDbConnection conObj = new OleDbConnection(); conObj.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\j\My Documents\MyDb.mdb"; conObj.Open(); OleDbCommand cmdObj = new OleDbCommand(); cmdObj.CommandText = "select Name from MyTable"; DataSet ds = new DataSet(); cmdObj.Connection = conObj; OleDbDataAdapter adapObj = new OleDbDataAdapter(); adapObj.SelectCommand = cmdObj; adapObj.Fill(ds); } } }
In future posts, please use the
<code></code>
tags to make your code easier to read :-D"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
-
In future posts, please use the
<code></code>
tags to make your code easier to read :-D"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
Paul Conrad wrote:
please use the <code></code> tags
Absolutely not. Don't use CODE tags for multi-line stuff, they are for single-line things only. Multi-line code should be in PRE tags which preserves formatting. With two caveats: - empty lines disappear, so add a space tot them - less-than signs followed by a letter will be eaten by the HTML deamon, therefore replace < by < :)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
-
Paul Conrad wrote:
please use the <code></code> tags
Absolutely not. Don't use CODE tags for multi-line stuff, they are for single-line things only. Multi-line code should be in PRE tags which preserves formatting. With two caveats: - empty lines disappear, so add a space tot them - less-than signs followed by a letter will be eaten by the HTML deamon, therefore replace < by < :)
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips: - before you ask a question here, search CodeProject, then Google; - the quality and detail of your question reflects on the effectiveness of the help you are likely to get; - use PRE tags to preserve formatting when showing multi-line code snippets.
That's right, my bad. I remember we did a big investigation on this last summer :-D I thought it was
pre
andcode
together."What's your question? All I see is some deranged, half-assed looking run-on sentence. Where are you having problems?" - Justin Perez
-
That's right, my bad. I remember we did a big investigation on this last summer :-D I thought it was
pre
andcode
together."What's your question? All I see is some deranged, half-assed looking run-on sentence. Where are you having problems?" - Justin Perez
-
someone should sticky this..I keep forgetting.
Steve Welborn Software Engineer Inrange Consulting
Look at Luc's article he did on the topic.
"I guess it's what separates the professionals from the drag and drop, girly wirly, namby pamby, wishy washy, can't code for crap types." - Pete O'Hanlon
-
Hello, Am trying to bind data.This is my code.Is there any problem with my code since it does not seem to work. Take your time. Thanking You using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; namespace TestDb { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void btnInsert_Click(object sender, EventArgs e) { OleDbConnection conObj = new OleDbConnection(); conObj.ConnectionString=@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\j\My Documents\MyDb.mdb"; conObj.Open(); OleDbCommand cmdObj = new OleDbCommand(); cmdObj.CommandText = "Insert into MyTable(Name) values ('" + txtName.Text + "')"; cmdObj.Connection = conObj; cmdObj.ExecuteNonQuery(); txtName.Clear(); } private void btnBind_Click(object sender, EventArgs e) { OleDbConnection conObj = new OleDbConnection(); conObj.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\j\My Documents\MyDb.mdb"; conObj.Open(); OleDbCommand cmdObj = new OleDbCommand(); cmdObj.CommandText = "select Name from MyTable"; DataSet ds = new DataSet(); cmdObj.Connection = conObj; OleDbDataAdapter adapObj = new OleDbDataAdapter(); adapObj.SelectCommand = cmdObj; adapObj.Fill(ds); } } }
Trustapple wrote:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb;
Can you paste the code of libraries you used as well?
Do rate the reply, if it helps or even if it doesnot, because it helps the members to know, what solved the issue. Thanks.