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
vutharadi prathyusha
NA
18
26.5k
Sql Connection error
Sep 12 2015 7:27 AM
Hi,
Iam new to c# create sample form but iam getting where i made a mistake if any one please help me.
Here is the code
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication7
{
public partial class task1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void subbtn_Click(object sender, EventArgs e)
{
// lblresult.Text=fnametxt.Text+ " " +lnametxt.Text+ " " +yeardropdown.SelectedItem.Text+ " " +monthdropdown.SelectedItem.Text+ " " +daydropdown.SelectedItem.Text+ " " +quadropdown.SelectedItem.Text+ " " +CheckBox1.Text+ " " ;
assingValues();
sqlconnection con=new sqlconnection("Data Source=MURALI\SQLEXPRESS;Initial Catalog=test;Integrated Security=True");
sqlcommand cmd=new sqlcommand("Insert into sampleform(FName,LName,Gender,Year,Month,Day,Qualification,check)values(@FName,@LName,@Gender,@Year,@Month,@Day,@Qualification,@check)");
con.Open();
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@FName", fnametxt.Text);
cmd.Parameters.AddWithValue("@LName", lnametxt.Text);
cmd.Parameters.AddWithValue("@Gender", radioGeder.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Year", yeardropdown.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Month", monthdropdown.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Day", daydropdown.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Qualification", quadropdown.SelectedItem.Text);
cmd.Parameters.AddWithValue("@check", monthdropdown.SelectedItem.Text);
cmd.Parameters.AddWithValue("@Day", check.Checked);
// cmd.Parameters.Add("FName", SqlDbType.VarChar);
//cmd.Parameters["FName"].Value = fnametxt.Text;
//cmd.Parameters.Add("LName", SqlDbType.VarChar);
//cmd.Parameters["LName"].Value = lnametxt.Text;
//cmd.Parameters.Add("Gender", SqlDbType.VarChar);
//cmd.Parameters["Gender"].Value = radioGeder.SelectedItem.Text;
//cmd.Parameters.Add("Year", SqlDbType.Int);
//cmd.Parameters["Year"].Value = yeardropdown.SelectedItem.Text;
//cmd.Parameters.Add("Month", SqlDbType.Int);
//cmd.Parameters["Month"].Value = monthdropdown.SelectedItem.Text;
//cmd.Parameters.Add("Day", SqlDbType.Int);
//cmd.Parameters["Day"].Value = daydropdown.SelectedItem.Text;
//cmd.Parameters.Add("Qualification", SqlDbType.VarChar);
//cmd.Parameters["Qualification"].Value = quadropdown.SelectedItem.Text;
//cmd.Parameters.Add("check", SqlDbType.VarChar);
//cmd.Parameters["check"].Value = check.Checked;
cmd.ExecuteNonQuery();
con.Close();
}
protected void clearbtn_Click(object sender, EventArgs e)
{
fnametxt.Text = "";
lnametxt.Text = "";
yeardropdown.SelectedItem.Text = "Year";
monthdropdown.SelectedItem.Text = "Month";
daydropdown.SelectedItem.Text = "Day";
quadropdown.SelectedItem.Text = "Select";
check.Checked = false;
}
public string FName { get; set; }
public string LName { get; set; }
public string Gender { get; set; }
public string Year { get; set; }
public string Month { get; set; }
public string Day { get; set; }
public string Qualification { get; set; }
public void assingValues()
{
FName = fnametxt.Text;
LName = lnametxt.Text;
Gender = radioGeder.SelectedItem.Text;
Year = yeardropdown.SelectedItem.Text;
Month = monthdropdown.SelectedItem.Text;
Day = daydropdown.SelectedItem.Text;
Qualification = quadropdown.SelectedItem.Text;
lblresult.Text = "First Name :" + FName + " Last Name :" + LName + "Gender:" + Gender + "Year:" + Year + "Month:" + Month + "Day:" + Day + "Qualification:" + Qualification;
if (check.Checked == true)
{
lblresult.Text = lblresult.Text+"Terms and Conditions.";
}
}
}
}
This is the error i'm getting..
Error 4 The type or namespace name 'sqlcommand' could not be found (are you missing a using directive or an assembly reference?) E:\Projects\samples\WebApplication7\WebApplication7\task1.aspx.cs 26 14 WebApplication7
Thanks,
Prathyusha.
Reply
Answers (
4
)
How to create an SQL SP with C# with line breaks
How to use Payment Gateway