I try to add data from a form to one of my SQL Server database table. I was reading all the materials on stack but it seems I am doing something wrong I can't see.
Simple code to add data, no luck
Web form
<%# Page Language="C#" AutoEventWireup="true"
CodeBehind="Reports.aspx.cs"
Inherits="WAPReview.Reports" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label CssClass="label" ID="Label7" runat="server" Text="Name" />
<asp:TextBox CssClass="textbox" ID="TextBox1" runat="server" />
<p>
<asp:Button ID="Button" runat="server" Text="Save Data" />
</p>
</div>
</form>
</body>
</html>
C# code:
using System;
using System.Configuration;
using System.Data.SqlClient;
namespace WAPReview
{
public partial class Reports : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button_Click(object sender, EventArgs e)
{
string connectionString = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString;
SqlConnection conn = new SqlConnection(connectionString);
string sqlInsert = "INSERT INTO tstTable (Name) VALUES (#Name)";
using (SqlCommand command = new SqlCommand(sqlInsert, conn))
{
command.Parameters.AddWithValue("#Name", TextBox1.Text);
conn.Open();
command.ExecuteNonQuery();
conn.Close();
}
}
}
}
web.config for connection
<connectionStrings>
<add name="ConnString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\WAPReview.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I think you did not generate onclick event of button properly replace button code by below
<asp:Button ID="Button" OnClick="Button_Click" runat="server" Text="Save Data" />
and check it using breakpoint on the click event if code is executing or not.
pls check with
string connectionString = ConfigurationManager.ConnectionStrings["ConnString"].tostring();
also add parathasis to webconfig connection string
<add name="ConnString" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\WAPReview.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
Related
I want the method submit_click to be activated when the submit button on the HTML part is pressed
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Debug="true" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" method="post" onsubmit="Submit_Click">
mail<br />
<asp:TextBox ID="mail" runat="server" Style="margin-left: 0px">mail</asp:TextBox>
<br />
name<br />
<asp:TextBox ID="name" runat="server" Width="117px">name</asp:TextBox>
<br />
last
<br />
<asp:TextBox ID="last" runat="server">name</asp:TextBox>
<p>
pass
</p>
<p>
<asp:TextBox ID="password" runat="server">password</asp:TextBox>
</p>
id <p>
<asp:TextBox ID="id1" runat="server">id</asp:TextBox>
</p>
<input id="Submit" type="submit" value="submit" onserverclick="Submit_Click()" />
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Submit_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection(#"Provider=Microsoft.ACE.OLEDB.12.0; Data source = " + Server.MapPath("") + "\\Database.accdb");
conn.Open();
string com = "INSERT into myusers (myid,myname,mymail,mypass,mylast) VALUES ('" + id1.Text + "," +name.Text + "," + mail.Text + "," +password.Text + "," + last.Text + "')";
OleDbCommand comm = new OleDbCommand(com, conn);
comm.ExecuteNonQuery();
conn.Close();
}
}
Actually why you're doing this , that i don't know because Asp Button will also converted like below on browser side, Still if you want to use it put runat="server", try below code.
<input id="Submit" runat="server" type="submit" value="submit" onserverclick="Submit_ServerClick" />
You are missing 'runat="server"'. Include it in the submit control.
hi I am trying to make a log in page as well as sign up page in asp.net using 3 tier architecture by using sql server architecture. I am able to fetch data from sql server data base which I have manually inserted during table creation in database and I am able to use it in my log in page.
I have also created a sign up page but I am not able to get the values from sign up webform textbox to sqlserver database I am getting some error kindly help me with this.
I have given the connection string of sql server in web.config
my sql server table creation code
CREATE TABLE LOGINDETAILS
(USERID VARCHAR(50),
PASSWORD VARCHAR (50)
);
INSERT INTO LOGINDETAILS (USERID,PASSWORD) values( 'sam', 'pass');
web.config connection string code
<?xml version="1.0"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<connectionStrings>
<add name="DBcon" connectionString="Data Source=P3A-B1YH882\SQLSERVER;Initial Catalog=master;Integrated Security=True" providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
</configuration>
my business layer /middle layer code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using DataAcess;
using System.Data.SqlClient;
using System.Data.Sql;
namespace middlelayer
{
public class UserBO
{
private string _UserName = " ";
public string UserName
{
get { return _UserName; }
set { _UserName = value; }
}
private string _Password = " ";
public string Password
{
get { return _Password; }
set { _Password = value; }
}
DataA da = new DataA();
public bool getUser()
{
if (da.IsValid(UserName, Password).Tables[0].Rows.Count == 0)
{
return false;
}
else
{
return true;
}
}
}
}
my datAccess layer code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
namespace DataAcess
{
public class DataA
{
string conString = ConfigurationManager.ConnectionStrings["DBcon"].ToString();
public DataSet IsValid(string UserName, string Password)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM LOGINDETAILS WHERE USERID ='" + UserName + "' and PASSWORD= '" + Password + "'", con);
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(ds);
return ds;
}
}
}
MY LOGIN PAGE CODE
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="login.aspx.cs" Inherits="WebApplication4.login" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body style="height: 277px">
<form id="form1" runat="server">
<div>
<asp:Label ID="lbluserid" runat="server" BackColor="#FFFF99" BorderStyle="Ridge" Height="17px" Text="User ID" Width="52px"></asp:Label>
<asp:TextBox ID="txtuserid" runat="server" BackColor="#99FFCC" style="margin-left: 122px"></asp:TextBox>
<br />
</div>
<p>
<asp:Label ID="lblpassword" runat="server" BackColor="#FFFF99" BorderStyle="Ridge" Text="Password"></asp:Label>
<asp:TextBox ID="txtpassword" TextMode="Password" runat="server" BackColor="#99FFCC" style="margin-left: 110px" ></asp:TextBox>
</p>
<p>
</p>
<asp:Button ID="btnlogin" runat="server" BackColor="#33CCFF" BorderStyle="Ridge" OnClick="btnlogin_Click" style="margin-left: 78px" Text="Login" Width="107px" />
<p>
</p>
<asp:Label ID="Label1" runat="server" Text="NOT REGISTERED ??"></asp:Label>
<asp:HyperLink ID="HyperLink1" runat="server" BorderStyle="Outset" NavigateUrl="~/sign_up.aspx">SIGN UP</asp:HyperLink>
</form>
</body>
</html>
* MY SIGN UP PAGE CODE*
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="sign_up.aspx.cs" Inherits="WebApplication4.sign_up" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Label ID="lblssignup" runat="server" BackColor="#FF99CC" Text="SIGN UP"></asp:Label>
<br />
<br />
<p>
<asp:Label ID="lblsuserid" runat="server" Text="ENTER USER ID"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" style="margin-bottom: 0px"></asp:TextBox>
</p>
<asp:Label ID="lblspassword" runat="server" Text="ENTER PASSWORD"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
<p>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" Width="66px" />
</p>
</form>
</body>
</html>
SIGN UP PAGE BUTTON CODE FOR ENTERING DATA INTO SQL SERVER DATABASE ON BUTTON CLICK
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using middlelayer;
namespace WebApplication4
{
public partial class sign_up : System.Web.UI.Page
{
string conString = ConfigurationManager.ConnectionStrings["DBcon"].ToString();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(conString);
con.Open();
string ins= "Insert into [LOGINDETAILS](USERID, PASSWORD) VALUES ('" +TextBox1.Text+ "' , '" +TextBox2.Text+ "')";
SqlCommand com = new SqlCommand(ins,con);
DataSet du = new DataSet();
SqlDataAdapter sdi = new SqlDataAdapter(com);
sdi.Fill(du);
con.Close();
}
}
}
I AM getting error in this last code only of sign up button it is not able to insert values of SIGN UP webform Textbox to sql server databse table and also not reflecting the real values which I want to add in sql server TABLE using sign up webform and also noty saving it. It is sending some error values . kindly help me with this.
BELOW ARE THE IMAGES OF LOG IN AS WELL AS SIGN UP PAGE FOR REFERENCE
LOGIN PAGE WEB FORM
SIGN UP PAGE WEBFORM
KINDLY HELP IN RESOLVING THIS ISSUE
Try this:
SqlConnection con = new SqlConnection(conString);
con.Open();
string ins= "Insert into [LOGINDETAILS](USERID, PASSWORD) VALUES (#param1 , #param2)";
SqlCommand cmd = new SqlCommand(ins,con);
cmd.Parameters.Add("#param1", SqlDbType.Varchar, 50).value = TextBox1.Text;
cmd.Parameters.Add("#param2", SqlDbType.Varchar, 50).value = TextBox2.Text;
cmd.CommandType = CommandType.Text;
cmd.ExecuteNonQuery();
con.Close()
When trying to register to my database I am receiving the "The name 'UName' does not exist in the current context" error.
Register.aspx:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Register.aspx.cs" Inherits="Register" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Registration Page</title>
</head>
<body>
<p>This is the registration page</p>
Home | Register
<form id="form1" runat="server">
<div>
<p>Enter First Name :</p>
<p>
<asp:TextBox ID="UName" runat="server" Width="271px"></asp:TextBox>
</p>
<p>
<asp:Button ID="registerButton" runat="server" Text="REGISTER" OnClick="registerEventMethod" />
</p>
</div>
</form>
</body>
</html>
Register.aspx.cs:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Register : System.Web.UI.Page
{
MySql.Data.MySqlClient.MySqlConnection conn;
MySql.Data.MySqlClient.MySqlCommand cmd;
String queryStr;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void registerEventMethod(object sender, EventArgs e)
{
registerUser();
}
private void registerUser()
{
String connString = System.Configuration.ConfigurationManager.ConnectionStrings["WebAppConnString"].ToString();
conn = new MySql.Data.MySqlClient.MySqlConnection(connString);
conn.Open();
queryStr = "";
queryStr = "INSERT INTO jamieobr_obecarrentals.users (Forename)" +
"VALUES('" + UName.Text + "')";
cmd = new MySql.Data.MySqlClient.MySqlCommand(queryStr, conn);
cmd.ExecuteReader();
conn.Close();
}
}
why am I getting this error? I have tried several solutions and all failed.
So I solved my own issue, the first initial issue was that I tried copying the .aspx file into a new solution, however this did not copy along the .aspx.designer.cs file therefore causing the problem.
However after trying to re write a fresh version manually which had a designer file with it I forgot to include the .cs file into the namespace of my solution therefore then generating a new problem.
However after including the .cs file into the namespace, hey presto, it worked!
I am inserting values into a web form and submitting the web form. The record gets inserted twice in my SQL Server 2014 database. My web form code and code behind logic are below.
I don't know why the record is being inserted twice into the database.
Web form code:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="register.aspx.cs" Inherits="register" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Social Login Form Flat Responsive widget Template :: w3layouts</title>
</head>
<body>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="Social Login Form Widget Responsive, Login form web template,Flat Pricing tables,Flat Drop downs Sign up Web Templates, Flat Web Templates, Login signup Responsive web template, Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyEricsson, Motorola web design" />
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script>
<!-- font files -->
<link href='/../fonts.googleapis.com/css?family=Muli:400,300' rel='stylesheet' type='text/css'>
<link href='/../fonts.googleapis.com/css?family=Nunito:400,300,700' rel='stylesheet' type='text/css'>
<!-- /font files -->
<!-- css files -->
<link href="login.css" rel='stylesheet' type='text/css' media="all" />
<!-- /css files -->
</head>
<body>
<h1>Social Login Form</h1>
<div class="log">
<div class="social w3ls">
<li class="f"><img src="images/fb.png" alt=""></li>
<li class="t"><img src="images/twt.png" alt=""></li>
<li class="p"><img src="images/pin.png" alt=""></li>
<li class="i"><img src="images/ins.png" alt=""></li>
<div class="clear"></div>
</div>
<div class="content2 w3agile">
<h2>Sign Up</h2>
<form ID="form" runat="server" method="post">
<asp:TextBox ID="name" runat="server" placeholder="Name Surname" pattern="[A-Za-z]+\s[A-Za-z]+" title="Firstname Surname" required></asp:TextBox>
<asp:TextBox ID="username" runat="server" placeholder="Username" title="Username" required></asp:TextBox>
<asp:TextBox ID="phoneno" runat="server" placeholder="Phone Number" pattern="[7-9]{1}[0-9]{9}" required title="Phone number starting with 7-9 and remaing 9 digit with 0-9"></asp:TextBox>
<asp:TextBox ID="email" type="email" runat="server" placeholder="Email Address" required ></asp:TextBox>
<asp:TextBox ID="password" runat="server" type="password" placeholder="Password" required title="Any number of characters or special characters"></asp:TextBox>
<input id="confirm_password" placeholder="Confirm Password" runat="server" type="password" required title="Any number of characters or special characters"></input>
<script type="text/javascript">
var password = document.getElementById("password")
, confirm_password = document.getElementById("confirm_password");
function validatePassword() {
if (password.value != confirm_password.value) {
confirm_password.setCustomValidity("Passwords Don't Match");
} else {
confirm_password.setCustomValidity('');
}
}
password.onchange = validatePassword;
confirm_password.onkeyup = validatePassword;
</script>
<asp:Button ID="Button1" runat="server" Text="Sign up" class="register" OnClick="btn_Click" />
<h3>Already have an account? Sign In</h3>
</div>
</div>
<div class="footer">
<p>© 2016 Social Login Form. All Rights Reserved | Design by w3layouts</p>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>
Code behind:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class register : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btn_Click(object sender, EventArgs e)
{
int userId = 0;
SqlConnection con = new SqlConnection(#"Data Source=RISHIK\SQLEXPRESS;Initial Catalog=Register;Integrated Security=True");
String query = "Insert into Table_2 values('"+name.Text+"','"+username.Text+"','"+phoneno.Text+"','"+email.Text+"','"+password.Text+"')";
con.Open();
SqlCommand cmd = new SqlCommand(query, con);
userId = Convert.ToInt32(cmd.ExecuteScalar());
cmd.ExecuteNonQuery();
//Label1.Text = "Hjg";
con.Close();
}
}
this line
userId = Convert.ToInt32(cmd.ExecuteScalar());
is not doing what you think. it will execute the insert statement and then return a scalar value.
then your next line:
cmd.ExecuteNonQuery();
will insert the record again
this is what Blorgbeard is trying to tell you.
that is why it is inserting twice.
also - you should consider parameterizing that query. taking the value of your user input and creating your query with those values without checking them is just begging for a sql injection attack
Use parameterised query , something like....
int userId = 0;
SqlConnection con = new SqlConnection(#"Data Source=RISHIK\SQLEXPRESS;Initial Catalog=Register;Integrated Security=True");
SqlCommand cmd = new SqlCommand("Insert into Table_2 values(#Name, #UserName, #Phone, #Email, #Password);
SELECT CAST(scope_identity() AS int)", con);
cmd.Parameters.AddWithValue("#Name", name.Text);
cmd.Parameters.AddWithValue("#UserName", username.Text);
cmd.Parameters.AddWithValue("#Phone", phoneno.Text);
cmd.Parameters.AddWithValue("#Email", email.Text);
cmd.Parameters.AddWithValue("#Password", password.Text);
con.Open();
userId = (Int)cmd.ExecuteScalar();
I have two text boxes that should be getting filled with Ajax AutoCompleteExtender information. One text done with a Web Service and the other is a code behind Web Method. The Web Service one is for Customer IDs; If I start my page with the web service and put in a number for the ID it works and gives me all of the information but if I try to do it in my actual asp.net form then nothing happens when I type in a number to for my search criteria. Also, for the Web Method from the code behind doesn't seem to find anything for me when I type a letter...... I'm wondering if I am missing a reference or something that is making my actual web page not fetch the data or am I just doing it wrong as this is my first time using this.
I am using Visual Studio 2012
asp.net webform
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Orders.aspx.cs" Inherits="TropicalServer.UI.Orders" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<link type="text/css" rel="stylesheet" href="~/AppThemes/TropicalStyles/Orders.css" />
<title>Orders Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<!-- Criteria Bar -->
<div>
<table>
<tr>
<td>
<asp:Label ID="lblOrderDate" runat="server" Text="Order Date: "></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlOrderDate" runat="server"></asp:DropDownList>
</td>
<td>
<asp:Label ID="lblCustID" runat="server" Text="Customer ID: "></asp:Label>
</td>
<td>
<asp:TextBox ID="tbCustID" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="aceCustID" runat="server"
ServicePath="wsOrders.asmx"
TargetControlID="tbCustID"
MinimumPrefixLength="1"
CompletionInterval="100"
CompletionSetCount="1"
ServiceMethod="GetCustomerID"
UseContextKey="true"
EnableCaching="true"> </ajaxToolkit:AutoCompleteExtender>
</td>
<td>
<asp:Label ID="lblCustName" runat="server" Text="Customer Name: "></asp:Label>
</td>
<td>
<asp:TextBox ID="tbCustName" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="aceCustName" runat="server"
TargetControlID="tbCustName"
MinimumPrefixLength="1"
EnableCaching="true"
CompletionInterval="1000"
CompletionSetCount="1"
UseContextKey="True"
ServiceMethod="GetCustomerName">
</ajaxToolkit:AutoCompleteExtender>
</td>
<td>
<asp:Label ID="lblSalesManager" runat="server" Text="Sales Manager: "></asp:Label>
</td>
<td>
<asp:DropDownList ID="ddlSalesManager" runat="server"></asp:DropDownList>
</td>
</tr>
</table>
</div>
<!-- End Criteria -->
Code Behind asp.net
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using TropicalServer.DAL;
namespace TropicalServer.UI
{
public partial class Orders : System.Web.UI.Page
{
#region Declerations
DALConnection TropConnection;
#endregion
#region Constructor
public Orders()
{
TropConnection = new DALConnection();
}
#endregion
protected void Page_Load(object sender, EventArgs e)
{
}
#region WebMethod
[System.Web.Script.Services.ScriptMethod()]
[System.Web.Services.WebMethod]
public List<string> GetCustomerName(string prefixText)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "spCustName";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#CustName", prefixText);
cmd.Connection = TropConnection.GetConnection();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
List<string> CustomerNames = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
CustomerNames.Add(dt.Rows[i]["CustName"].ToString());
}
return CustomerNames;
}
#endregion
}
}
Web Service
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using TropicalServer.DAL;
namespace TropicalServer
{
/// <summary>
/// Summary description for wsOrders
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class wsOrders : System.Web.Services.WebService
{
#region Declerations
DALConnection TropConnection;
#endregion
#region Constructor
public wsOrders()
{
TropConnection = new DALConnection();
}
#endregion
//"SELECT * FROM tblOrder WHERE OrderCustomerNumber LIKE #CustID+'%'"
[WebMethod]
public List<string> GetCustomerID(string prefixText)
{
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "spCustID";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("#CustID", prefixText);
cmd.Connection = TropConnection.GetConnection();
SqlDataAdapter sda = new SqlDataAdapter(cmd);
sda.Fill(dt);
List<string> CustomerIDs = new List<string>();
for (int i = 0; i < dt.Rows.Count; i++)
{
CustomerIDs.Add(dt.Rows[i]["OrderCustomerNumber"].ToString());
}
return CustomerIDs;
}
}
}
WEB CONFIG
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="TropicalServerConnectionString" value="Initial Catalog=TropicalServer;Data Source=Nicolas-PC\SQLEXPRESS;Integrated Security=true;" />
</appSettings>
<connectionStrings>
<add name="TropicalServerConnectionString" providerName="System.Data.SqlClient" connectionString="Data Source=Nicolas-PC;Initial Catalog=TropicalServer;Integrated Security = true" />
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
<add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</assemblies>
</compilation>
<authentication mode="Forms">
<!--<forms loginUrl="~/Account/Login.aspx" timeout="2880" />-->
</authentication>
<pages>
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages></system.web>
</configuration>
I think your problem is with your method signature. If you have UseContextKey="True", the method should be:
public static string[] GetCustomerID(string prefixText, int count, string contextKey)
{
}
If UseContextKey="False", the method should be:
public static string[] GetCustomerID(string prefixText, int count)
{
}