943,703 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 7102
  • ASP.NET RSS
Nov 14th, 2008
0

error

Expand Post »
i taken the three textboxes and one button to store the data in sqlserver .but the it giving the error.
the code is as follows...


ASP.NET Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Data.SqlClient;
  12.  
  13. public partial class Default3 : System.Web.UI.Page
  14. {
  15. protected void Page_Load(object sender, EventArgs e)
  16. {
  17. SqlConnection con = new SqlConnection("user id=sa;password=vikram;database=kran");
  18. SqlCommand cmd = new SqlCommand("select * from dr", con);
  19. SqlDataReader dr;
  20. // cmd.CommandText = "select * from dr";
  21. cmd.Connection = con;
  22. con.Open();
  23. dr = cmd.ExecuteReader();
  24. cmd.CommandText="insert into dr values("&TextBox1.Text&", ' " &TextBox2.Text&" ', ' " &TextBox3.Text&" ')";
  25. TextBox1.Text=" ";
  26. TextBox2.Text= " ";
  27. TextBox3.Text=" ";
  28. dr.Close();
  29. con.Close();
  30.  
  31.  
  32.  
  33. }
  34. protected void Button1_Click(object sender, EventArgs e)
  35. {
  36.  
  37. }
  38. }

i written the code like that .please clarify my application..
if it is not correct please tel me the correct...
Last edited by peter_budo; Nov 14th, 2008 at 8:09 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krany18 is offline Offline
19 posts
since Nov 2008
Nov 14th, 2008
0

Re: error

Hi, You use the same SqlCommand variable to read and execute query.
Please create new SqlCommand variable to execute query...

Thanks,
Reputation Points: 11
Solved Threads: 17
Junior Poster
Kusno is offline Offline
191 posts
since Aug 2007
Nov 14th, 2008
0

Re: error

please tell me the exact code,,
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krany18 is offline Offline
19 posts
since Nov 2008
Nov 14th, 2008
0

Error 1 Operator '&' cannot be applied to operands of type 'string' and 'string'

hai to all,,
once again i am sending the same code.but it giving same problem.please rectify my problem .it is urgent to me...
using System;
using System.Data;
using System.Configuration;
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;

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

        SqlConnection con = new SqlConnection("user id=sa;password=vikram;database=kum");
        SqlCommand cmd = new SqlCommand(" ", con);
        con.Open();
        con.Close();
        



    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con=new SqlConnection("user id=sa;password=vikram;database=kum");
        SqlCommand cmd=new SqlCommand();
        cmd.CommandText = "insert into kumar values( " & TextBox1.Text & " ,' " & TextBox2.Text & " ')";
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        TextBox1.Text = " ";
        TextBox2.Text=" ";


    }
}
Error comes at bold line code..
please forward me a correct code..
Last edited by peter_budo; Nov 14th, 2008 at 8:11 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
krany18 is offline Offline
19 posts
since Nov 2008
Nov 14th, 2008
0

Re: Error 1 Operator '&' cannot be applied to operands of type 'string' and 'string'

use "+" instead of "&"
like

cmd.CommandText = "insert into kumar values( " + TextBox1.Text + " ,' " + TextBox2.Text + " ')";
Reputation Points: 10
Solved Threads: 9
Junior Poster
sierrainfo is offline Offline
144 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Page.RegisterClientScriptBlock
Next Thread in ASP.NET Forum Timeline: need to populate the single column out of mulitple colums,





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC