Asp.Net News
Free Tech Magazines
Asp.Net Web Hosting
Suggest Us
Link to Us
Feeds Subscription
Questions & Answers
Tips & Tricks
 When iam creating update and showing error about sqldatareader
Posted by Raghunandan on  5/11/2010 9:36:00 AM Category: Asp.Net 2.0
Add to my favorites
Email to friend
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Windows.Forms;

public partial class Update : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
SqlConnection con = new SqlConnection("Data Source= seed-44; Initial Catalog=LoginData;User Id=sa; Password=default");
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;

cmd.CommandType = CommandType.Text;
int i = Convert.ToInt32(DropDownList1.Text);
cmd.CommandText = "Select SpeakerId From AdminTable where Speakerid=" + DropDownList1.SelectedValue;

SqlDataReader dr= cmd.ExecuteReader();
if (dr.HasRows)
TextBox1.Text = dr["Name"].ToString();
TextBox2.Text= dr["LastName"].ToString();
TextBox3.Text= dr["Address"].ToString();
TextBox4.Text= dr["ContactNo"].ToString();
TextBox5.Text= dr["TagLine"].ToString();
TextBox6.Text= dr["SpeechTitle"].ToString();
TextBox7.Text= dr["Biography"].ToString();
TextBox8.Text= dr["EmailId"].ToString();

protected void Button1_Click(object sender, EventArgs e)
string s = ConfigurationManager.ConnectionStrings["LoginDataConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(s);
int i = Convert.ToInt32(DropDownList1.SelectedValue);
SqlDataAdapter da = new SqlDataAdapter("Update from AdminTable set Address='" + TextBox3.Text + "',ContactNo=" + TextBox4.Text + "TagLine=" + TextBox5.Text + "SpeechTitle=" + TextBox6.Text + " where AdminTable=" + i + "", con);
DataSet ds = new DataSet();
da.Fill(ds, "Admin");
MessageBox.Show("Update Succesefully");

Post Your Reply Post New Question

 Viewer's Reply
Update Data in Database using SqlCommand
Answered By Moderator1 on 5/12/2010 9:46:16 AM

First of all, you must be always be little bit elaborate on your question.. A single line description is not enough to identity your problem..

To update the data into data use SqlCommand with ExecuteNonQuery method.. SqlDataAdapter won't help you to update data into database.
Post Your Reply If you still have problem, post it again under this reply for better response.

Sponsored by
Washington Technology
Introduction to Web Applications Development
The PHP Anthology: 101 Essential Tips, Tricks & Hacks, 2nd Edition - Free 207 Page Preview!