So... I have 3 textboxes and a Submit button. Here's the code behind:

public void Submit1_onClick(object sender, EventArgs e)
    {
        SqlConnection conn = new SqlConnection();
        DateTime laiks = new DateTime();
        conn.ConnectionString = "data source=.;initial catalog=ForumDataBase;integrated security=true;";
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "INSERT INTO PostTable(ThreadTitle,PostMessage,UserName) values('" & ThreadTextbox.Value & "','" & PostTextbox.Value & "','" & UserNameTextBox.Value & "')";
        cmd.Connection = conn;
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
    }

I don't quite understand SQL syntax used in ASP.NET or wherever so I don't know how to write it properly, but the main problem is that I'm getting this error:
Error 1 The name 'ThreadTextbox' does not exist in the current context
(For all textboxes)
The id's and titles are OK for all textboxes...
So can you tell me what's the problem?


I guess it's because the posts.aspx is not connected with posts.aspx.cs file or something like that, but I've no ideas how to fix it...

Recommended Answers

Hi,
One of the differance between asp.net with vb and asp.net with c# is that ,u …

Jump to Post

wat controls are u using html or sever controls.if u are using html controls convert that into server control by adding runat=server in the html control.

Jump to Post

All 6 Replies

Hi,
One of the differance between asp.net with vb and asp.net with c# is that ,u should use '+' instead of '&' in asp.net with c#.so make it a note,hope it helps u.

Sorry, that didn't help...

wat controls are u using html or sever controls.if u are using html controls convert that into server control by adding runat=server in the html control.

Thanks! That's the thing I needed!

hi,
mark this thread as solved if u r task is completed

Hi guys,

I tried the code and I fix it according to DB, But I still have a problem in it..

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CompanyInfo.aspx.cs" Inherits="CompanyInfo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    
<html runat="server" xmlns="http://www.w3.org/1999/xhtml" >



<head runat="server">
    <title>Untitled Page</title>
</head>



<body>

    <form id="form1" runat="server">
    <div>
        <span style="font-size: 36pt"><strong><span style="text-decoration: underline">Comany
            registration</span></strong><br />
        </span>
        <br />
       First Name:
        <asp:TextBox ID="NameTextBox" runat="server"></asp:TextBox>
        
        <asp:Button ID="SubmitButton" runat="server" Text="Submit" />

    
    </div>
       
        
        
    </form>
</body>
</html>

and this is the code behind it

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;

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

    }
    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {

    }
    protected void submitButton_Click(object sender, EventArgs e)
    {

        SqlConnection conn = new SqlConnection();
        DateTime laiks = new DateTime();
        conn.ConnectionString = "data source=.\\SQLEXPRESS;initial catalog=CV;integrated security=true;";
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "INSERT INTO Test(Firstname) values ('" & NameTextBox.Value & "')";
        cmd.Connection = conn;
        conn.Open();
        cmd.ExecuteNonQuery();
        conn.Close();
    }
    
  
    
}

I have the error in "Value" which is attached with "NameTextBox".
I have a database which is called "Test" and table with "Test" naming.
The colume name is "Firstname" with varchar(50) type
thanks in advance

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.