TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Brijendra Rawat
NA
27
6.7k
data not inserting in tables.
Sep 22 2016 11:08 PM
hello sir / madam,
i am new to c#.net and i like to program,i have a table named login which have id,username and password columns, i also have a login form to send data in Login table i want to store input data in table but i am receiving the error - " An unhandled exception of type 'System.ArgumentException' occurred in System.Data.dll". what am i doing wrong? i am using visual studio 2015.please help! thank you.here is my code -
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace login
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnLogin_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Log.mdf;Integrated Security=True;Connect Timeout=30;");
SqlDataAdapter sda = new SqlDataAdapter("Select Count (*) From Login where username ='" + userNametextBox.Text + "'and password='" + PasswordtextBox.Text + "'", con);
DataTable dt = new DataTable();
sda.Fill(dt);
if (dt.Rows[0][0].ToString() == "1")
{
this.Hide();
Main ss = new Main();
ss.Show();
}
else
{
MessageBox.Show("Please check your username and password ");
}
}
private void btnInsert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Log.mdf;Integrated Security=True;Connect Timeout=30;");
SqlDataAdapter sda = new SqlDataAdapter("Select Count (*) From Login where username ='" + userNametextBox.Text + "'and password='" + PasswordtextBox.Text + "'", con);
SqlCommandBuilder cmb = new SqlCommandBuilder(sda);
//DataTable dt = new DataTable();
DataSet ds = new DataSet();
sda.Fill(ds, "Login");
ds.Tables[0].Constraints.Add("Id", ds.Tables[0].Columns[0], true);
DataRow row;
row = ds.Tables[0].NewRow();
row["username"] = userNametextBox.Text;
row["password"] = PasswordtextBox.Text;
ds.Tables[0].Rows.Add(row);
sda.Update(ds.Tables[0]);
MessageBox.Show("record added", this.Text);
}
private void userNametextBox_TextChanged(object sender, EventArgs e)
{
}
}
}
Reply
Answers (
1
)
How to SQLite connect Visual Studio 2012?
How to get dropdown selected id data in table grid in Angula