15,893,668 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by codingisok101 (Top 36 by date)
codingisok101
25-Aug-12 1:56am
View
i dont have the option of using databind. it isnt recognised.
codingisok101
25-Aug-12 1:53am
View
i dont have the databind function.
codingisok101
25-Aug-12 1:49am
View
when i click on the button, i want the sql query to be executed and the resulting table to be displayed on a gridview.
but when i click on the button, it just shows the table colums. no data is displayed.
codingisok101
24-Aug-12 8:57am
View
i tried this. the error is rectified! thanks
codingisok101
24-Aug-12 8:50am
View
sure! thanks for the tip!
codingisok101
24-Aug-12 8:43am
View
this is my code. where am i going wrong?
codingisok101
24-Aug-12 8:35am
View
namespace final2
{
public partial class Form1 : Form
{
private SqlConnection con;
private SqlCommand command;
private SqlDataAdapter adapter;
private DataSet dataset;
public DataGridView dg;
public Form1()
{
InitializeComponent();
con = new SqlConnection();
command = con.CreateCommand();
con.ConnectionString = "Data Source=CASSINI-003-PC;Initial Catalog=studentdb;Integrated Security=True";
adapter = new SqlDataAdapter(command);
dataset = new DataSet();
}
private void button1_Click(object sender, EventArgs e)
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@StudentID", textBox1.Text);
command.Parameters.AddWithValue("@Name", textBox2.Text);
command.Parameters.AddWithValue("@Age", textBox3.Text);
command.Parameters.AddWithValue("@Gender", textBox4.Text);
command.Parameters.AddWithValue("@Courseno", listBox1.SelectedItem);
command.CommandText = "INSERT into details" + "(StudentID,Name,Age,Gender,Courseno)VALUES" + "(@StudentID,@Name,@Age,@Gender,@Courseno)";
try
{
con.Open();
int result = command.ExecuteNonQuery();
if (result > 0)
MessageBox.Show("student successfully updated");
else
MessageBox.Show("failed to update");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
ClearFields();
}
private void button2_Click(object sender, EventArgs e)
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@StudentID", textBox1.Text);
command.CommandText = "SELECT * FROM details WHERE StudentID=@StudentID";
dataset.Tables.Clear();
int result = adapter.Fill(dataset, "details");
if (result > 0)
{
DataRow srow = dataset.Tables["details"].Rows[0];
textBox1.Text = srow["StudentID"].ToString();
textBox2.Text = srow["Name"].ToString();
textBox3.Text = srow["Age"].ToString();
textBox4.Text = srow["Gender"].ToString();
listBox1.SelectedItem = srow["Courseno"].ToString();
}
else
{
MessageBox.Show("Student does not exist");
}
}
void ClearFields()
{
textBox1.Text = String.Empty;
textBox2.Text = String.Empty;
textBox3.Text = String.Empty;
textBox4.Text = String.Empty;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string currentitem = listBox1.SelectedItem.ToString();
}
private void button3_Click(object sender, EventArgs e)
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@Courseno", listBox1.SelectedValue);
command.CommandText = "SELECT * FROM results WHERE Courseno=1";
try
{
con.Open();
command.ExecuteNonQuery();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
adapter.Fill(dataset);
dataGridView1.DataSource = dataset;
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'studentdbDataSet1.result' table. You can move, or remove it, as needed.
this.resultTableAdapter.Fill(this.studentdbDataSet1.result);
}
}
}
this is my
codingisok101
24-Aug-12 8:31am
View
it says incorrect syntax near '='
codingisok101
24-Aug-12 8:00am
View
i need to output the data based on the item selected in the list box in one??
codingisok101
24-Aug-12 7:34am
View
amespace final2
{
public partial class Form1 : Form
{
private SqlConnection con;
private SqlCommand command;
private SqlDataAdapter adapter;
private DataSet dataset;
public DataGridView dg;
public Form1()
{
InitializeComponent();
con = new SqlConnection();
command = con.CreateCommand();
con.ConnectionString = "Data Source=CASSINI-003-PC;Initial Catalog=studentdb;Integrated Security=True";
adapter = new SqlDataAdapter(command);
dataset = new DataSet();
}
private void button1_Click(object sender, EventArgs e)
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@StudentID", textBox1.Text);
command.Parameters.AddWithValue("@Name", textBox2.Text);
command.Parameters.AddWithValue("@Age", textBox3.Text);
command.Parameters.AddWithValue("@Gender", textBox4.Text);
command.Parameters.AddWithValue("@Courseno", listBox1.SelectedItem);
command.CommandText = "INSERT into details" + "(StudentID,Name,Age,Gender,Courseno)VALUES" + "(@StudentID,@Name,@Age,@Gender,@Courseno)";
try
{
con.Open();
int result = command.ExecuteNonQuery();
if (result > 0)
MessageBox.Show("student successfully updated");
else
MessageBox.Show("failed to update");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
ClearFields();
}
private void button2_Click(object sender, EventArgs e)
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@StudentID", textBox1.Text);
command.CommandText = "SELECT * FROM details WHERE StudentID=@StudentID";
dataset.Tables.Clear();
int result = adapter.Fill(dataset, "details");
if (result > 0)
{
DataRow srow = dataset.Tables["details"].Rows[0];
textBox1.Text = srow["StudentID"].ToString();
textBox2.Text = srow["Name"].ToString();
textBox3.Text = srow["Age"].ToString();
textBox4.Text = srow["Gender"].ToString();
listBox1.SelectedItem = srow["Courseno"].ToString();
}
else
{
MessageBox.Show("Student does not exist");
}
}
void ClearFields()
{
textBox1.Text = String.Empty;
textBox2.Text = String.Empty;
textBox3.Text = String.Empty;
textBox4.Text = String.Empty;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string currentitem = listBox1.SelectedItem.ToString();
}
Form2 secondform=new Form2();
private void button3_Click(object sender, EventArgs e)
{
secondform.Show();
}
private void Form1_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'studentdbDataSet1.result' table. You can move, or remove it, as needed.
this.resultTableAdapter.Fill(this.studentdbDataSet1.result);
}
}
}
codingisok101
24-Aug-12 7:33am
View
my form one contains a list. based on the item selected, the data in form2 that is to be displayed has to change. for this i need to write an sql query. this is where im stuck. i dont know where to write this query.
codingisok101
24-Aug-12 7:00am
View
Solution 3 worked! Thanks!
codingisok101
24-Aug-12 6:59am
View
yep that was the mistake! Incorrect order! Thanks a lot!
codingisok101
24-Aug-12 6:52am
View
when i use this syntax it says invalid object name for the table name.
What do i do?
codingisok101
24-Aug-12 6:42am
View
see my problem is i cant select more than table in the datagrid source option. and i need to output the result of the sql query onto a datagrid. how do i do this?
codingisok101
24-Aug-12 6:30am
View
this is my entire code.
namespace final2
{
public partial class Form1 : Form
{
private SqlConnection con;
private SqlCommand command;
private SqlDataAdapter adapter;
private DataSet dataset;
public Form1()
{
InitializeComponent();
con = new SqlConnection();
command = con.CreateCommand();
con.ConnectionString = "Data Source=CASSINI-003-PC;Initial Catalog=studentdb;Integrated Security=True";
adapter = new SqlDataAdapter(command);
dataset = new DataSet();
}
private void button1_Click(object sender, EventArgs e)
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@StudentID", textBox1.Text);
command.Parameters.AddWithValue("@Name", textBox2.Text);
command.Parameters.AddWithValue("@Age", textBox3.Text);
command.Parameters.AddWithValue("@Gender", textBox4.Text);
command.Parameters.AddWithValue("@Courseno", listBox1.SelectedItem);
command.CommandText = "INSERT into details" + "(StudentID,Name,Age,Gender,Courseno)VALUES" + "(@StudentID,@Name,@Age,@Gender,@Courseno)";
try
{
con.Open();
int result = command.ExecuteNonQuery();
if (result > 0)
MessageBox.Show("student successfully updated");
else
MessageBox.Show("failed to update");
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message);
}
finally
{
con.Close();
}
ClearFields();
}
private void button2_Click(object sender, EventArgs e)
{
command.Parameters.Clear();
command.Parameters.AddWithValue("@StudentID", textBox1.Text);
command.CommandText = "SELECT * FROM details WHERE StudentID=@StudentID";
dataset.Tables.Clear();
int result = adapter.Fill(dataset, "details");
if (result > 0)
{
DataRow srow = dataset.Tables["details"].Rows[0];
textBox1.Text = srow["StudentID"].ToString();
textBox2.Text = srow["Name"].ToString();
textBox3.Text = srow["Age"].ToString();
textBox4.Text = srow["Gender"].ToString();
listBox1.SelectedItem = srow["Courseno"].ToString();
}
else
{
MessageBox.Show("Student does not exist");
}
}
void ClearFields()
{
textBox1.Text = String.Empty;
textBox2.Text = String.Empty;
textBox3.Text = String.Empty;
textBox4.Text = String.Empty;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string currentitem = listBox1.SelectedItem.ToString();
command.Parameters.Clear();
command.Parameters.AddWithValue("@Courseno", listBox1.Items);
command.CommandText = @"SELECT course.Courseno, subject.PaperName
FROM course INNER JOIN
ids ON course.Courseno = ids.Courseno INNER JOIN
subject ON ids.PaperID = subject.PaperID";
command.Parameters.Clear();
dataset.Tables.Clear();
adapter.Fill(dataset);
dataGridView1.DataSource = dataset;
}
}
}
codingisok101
24-Aug-12 6:29am
View
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
string currentitem = listBox1.SelectedItem.ToString();
command.Parameters.Clear();
command.Parameters.AddWithValue("@Courseno", listBox1.Items);
command.CommandText = @"SELECT course.Courseno, subject.PaperName
FROM course INNER JOIN
ids ON course.Courseno = ids.Courseno INNER JOIN
subject ON ids.PaperID = subject.PaperID";
command.Parameters.Clear();
dataset.Tables.Clear();
adapter.Fill(dataset);
dataGridView1.DataSource = dataset;
}
I am missing something here. I am unable to see anything in my datagridview
codingisok101
24-Aug-12 6:13am
View
i want to display this output on a gridview.. is it possible?
codingisok101
24-Aug-12 6:00am
View
from a list item
codingisok101
24-Aug-12 5:29am
View
how will this store the result in a table? if i drop it?
codingisok101
24-Aug-12 5:15am
View
SELECT course.Courseno, ids.PaperID
INTO courid
FROM course INNER JOIN
ids ON course.Courseno = ids.Courseno;
SELECT * FROM courid;
There is already an object named 'courid' in the database.
this is what i get as the error
codingisok101
24-Aug-12 3:37am
View
my listbox items are selected by an end user and those values are updated in the database.
codingisok101
24-Aug-12 3:21am
View
how do i pass the course no as a parameter in this case?
codingisok101
24-Aug-12 3:16am
View
but im selecting only one item at a time..
codingisok101
24-Aug-12 2:30am
View
my list has 1,2,3 etc.
this refers to the course id in my program
so how do i pass the course id as the item in the list?
codingisok101
24-Aug-12 2:14am
View
so is table1 not required?
codingisok101
24-Aug-12 2:04am
View
Select CourseName,PaperName from Table1,Table2 where table3.courseno=table1.courseno;
codingisok101
23-Aug-12 6:45am
View
no the problem was that everytime i entered one set of records, i could not enter another set of records even after clicking the button. the previous set of records still existed in the form
codingisok101
23-Aug-12 6:39am
View
Thanks a lot!
codingisok101
23-Aug-12 4:27am
View
there is no error in the code. My query is.. now i need to open a second windows form application using the value in the combo box. Im stuck on how to go forward from here.
codingisok101
22-Aug-12 8:18am
View
Thank u so much!
codingisok101
22-Aug-12 8:12am
View
so will txtname be the windows form text field in my case??
codingisok101
22-Aug-12 8:01am
View
hey Thanks for the logic!
I have a doubt.. what does txtName stand for?
and name?
codingisok101
22-Aug-12 7:50am
View
but i need to import the data from a database table.
how does a data table help??
codingisok101
22-Aug-12 7:11am
View
i could code partially. but with what i have coded till now, i am unable to proceed.
how do i proceed with binding the database to the form?
codingisok101
30-Jul-12 3:36am
View
Thanks:)
Show More