A Probelm With SqlConnection Command ....
Apr 19, 2005I have met a problem in the ASP.NET project creation with SQL Server Database Connection.
"Can't Login to My ServerName/ASPNET
How to solve the problem?
I have met a problem in the ASP.NET project creation with SQL Server Database Connection.
"Can't Login to My ServerName/ASPNET
How to solve the problem?
strsql = " select * from dic where english='" & SearchBox.Text Or TextBox4.Text & "'"The machine said Input string was not in a correct format. How can i select database with or operator in asp.net .Is it possible to select database in sql from more textbox ?
View 1 Replies View Relatedhi,I wrote this sp :CREATE PROCEDURE ins_AddOrder( @CartId NVARCHAR(50), @CustomerId INT, @OrderDate DATETIME, @OrderId INT OUTPUT)AS
DECLARE @ins_error INT, @sel_error INT, @var_rowcount INT
BEGIN TRAN AddOrder
INSERT INTO tbl_orders( customerId, orderDate)VALUES( @CustomerId, @OrderDate)
-- SET THE @@ERROR VALUE TO @ins_errorSELECT @ins_error =@@ERROR
/*IF INS_ERROR != 0BEGIN ROLLBACK TRAN RETURNEND*/
SELECT @OrderId = @@identity
INSERT INTO tbl_orderDetails( orderId, productId, quantity, productPrice)SELECT @OrderId, tbl_product.productId, quantity, tbl_product.productPriceFROM tbl_shoppingCartINNER JOIN tbl_product ON tbl_shoppingCart.productId = tbl_product.productIdWHERE cartId = @CartId
-- SET THE @@ERROR VALUE TO @sel_errorSELECT @sel_error = @@ERROR
-- SET THE @@ROWCOUNT TO @var_rowcountSELECT @var_rowcount = @@ROWCOUNT
IF @sel_error <> 0 OR @var_rowcount = 0 BEGIN ROLLBACK TRAN AddOrder RETURN ENDELSE BEGIN EXEC del_EmptyShoppingCart @CartId COMMIT TRAN AddOrder ENDGOIn the last few lines i try to prevent adding new row to tbl_orders (first statement), while the SELECT (second statement) does not return any row .It still not work.Can anyone help please?thanks.
I Have create a trigrer for my table transhd to update something in my detail table..
when i updated one record the trigger works fine..
but when i run command to update a batch of record in header
using command [update XXXX where cont] the trigger only fire for the last record in the batch..
is this the ms sql default behavior.. anyway to the around it
thanks in advance
I Have create a trigrer for my table transhd to update something in my detail table..
when i updated one record the trigger works fine..
but when i run command to update a batch of record in header
using command [update XXXX where cont] the trigger only fire for the last record in the batch..
is this the ms sql default behavior.. anyway to the around it
thanks in advance
I have a login in my sql server with windows authentication.When i tried to connet to the sql server with that login its not allowing me to connect even though I was logged on into my system.What should be the reason and what should i do?
View 2 Replies View RelatedHi , I just put my files up on a web server. I can view my aspx pages..but when I try to login to the website I get the following;
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Can you help? I can understand that it cannot find the specified instance of sql server, however I don't remember ever configuring it look to at a specific sql server. When i created the site in web dev express edition and added the login controls and set the asp config tool to use internet security it created the database itself and so I didn't have to put a connection string in. I also cannot see a connection string in tthe web.config file.
The aspnetdb.mdf file is there on the server. is this something i need to configure with the hosting company or do i set it in my webconfig file.
Thanks
I need to create some tables dynamically using sp_executesql. But the problem is the length of sql string is more the 4000 characters. How can I solve this problem?
Thanks
hello ![color=blue]>>> I am trying to intstall Mysql binary version with installor in Windows> XP machine . But it is not working . i have installed in the default> path ,in windows service componenet its showing server is running,since> it is mysqld-nt so name-piped servr is also running.>> But still client is able to connect to server.>> when i am tring to instal manually it is showing>> " service already exists;> the currect server intstalled is c:mysqlinmysqld-nt.exe>> when trying to connect to server> C:> c:mysqlinmysql test> ERROR 2003 : cannot connect to MYSQL server on localhost <10061>>> C:> telnet localhost 3306> connecting to localhost.......> could not open connection to host,on port 3306No connection shb ne made> because the target machine actibvely refused it.>> plz help me in installing ,pls clarify the problem.> pls reply soon.>>> regards> Smita[/color]
View 1 Replies View Related
We have a config table which has columns like pollingfolder, cop to folder etc.
Data looks like this
Config id polling folder
1 d:dataloadacn
2 d:dataloadship
under ACN and Ship folders we can have more than 1 source files which had to be loaded into target
the load process has to be repeated for each file in all the folders like ACN and ship
I have used for each loop container to poll the folder.
Can we set the directory to be polled at runtime taking from config table.
For doing this I have used the property Directory in expression editor of for each loop. But it is not working.
If I hard code the variable value in variables section , then its working.
How to change the directory to be polled value at runtime?
I had installed SQL server 2005 4 bit version. I created on SSIS package through export wizard.
the SSIS packages will transfer data from database to Excel file. But it is giving the below error.
Message
Executed as user: XXXXXSYSTEM. ... Utility Version 9.00.3042.00 for 64-bit Copyright (C) Microsoft Corp 1984-2005. All rights reserved. Started: 07:00:00 Error: 2008-05-14 07:00:00.51 Code: 0xC0202009 Source: Interface Connection manager "DestinationConnectionExcel" Description: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040154. An OLE DB record is available. Source: "Microsoft OLE DB Service Components" Hresult: 0x80040154 Description: "Class not registered". End Error Error: 2008-05-14 07:00:00.51 Code: 0xC00291EC Source: Preparation SQL Task Execute SQL Task Description: Failed to acquire connection "DestinationConnectionExcel". Connection may not be configured correctly or you may not have the right permissions on this connection. End Error DTExec: The package execution returned DTSER_FAILURE (1). Started: 07:00:00 Finished: 07:00:00 Elapsed: 0.344 seconds. The package execution failed. The step failed.
please any one guide me to reolve this issue.
I have two data sets but from the same data source. I created two different tables from these two data sets. Now I want to include a chart too. But When I insert the chart, it gives a erorr message.
The dinfinition of the report/my report name is invalid.
More than one data set, data region or grouping in the report has the name'chart1_seriesgroup1'. data set, data region and grouping names must be unique within a report.
Does any body know why this happen?
Thanks
Someone, please help me understand:
I have the following code:
Dim conString As String = ConfigurationManager.ConnectionStrings("WebAllianceConnectionString").ConnectionStringDim dsrc As New SqlDataSource()dsrc.ConnectionString = conStringdsrc.SelectCommandType = SqlDataSourceCommandType.StoredProceduredsrc.CancelSelectOnNullParameter = Falsedsrc.SelectCommand = "sp_GetCustomerInvoiceList"dsrc.SelectParameters.Clear()dsrc.SelectParameters.Add("@QueryType", "DATE")dsrc.SelectParameters.Add("@CustCode", "BAM7")dsrc.SelectParameters.Add("@OrdNumber", " ")dsrc.SelectParameters.Add("@InvStartDate", "1/1/2005")dsrc.SelectParameters.Add("@InvStopDate", "1/31/2005")dsrc.SelectParameters.Add("@PONumber", " ")Return dsrc.Select(DataSourceSelectArguments.Empty)
When this runs, it throws an exception:Prodecure or Function 'sp_GetCustomerInvoiceList' expects parameter '@QueryType', which was not supplied.
I'm confused... I clearly added that using the .Add method?What am I doing wrong?
has anyone had a problem restoring a SQL 2000 without sp1 to a SQL 2000 sp1 box or vice versa? I have had 2 failures telling me to call MS support in the message?
View 1 Replies View RelatedHi
Can i be able to use the DLL which is created in VB for Extended Stored Procedures.
if so how?
hi everyone,
How do i declare a global variable in my package which takes a numeric value like User::VAR1 = 200402 and later on work on it
Later in the properties of the Dataflow i want to have this expression..
"select * from " + "TAB1" + " where Date=" + @[User::VAR1]
Here i want to subtract 190000 from @[User::VAR1] to get it in to myformat i.e the DATE format in the table
I can only see String datatype and othe datatypes wont allow me to to do any kind of manipulation in the expression:
and to be more specific what are
Int16
Int32
Int64
Double
I tried to use all of the above but the expression doesnt allow me as once i use any of the above it says :
TITLE: Microsoft Visual Studio
------------------------------
Nonfatal errors occurred while saving the package:
Error at Extract: The data types "DT_WSTR" and "DT_I8" are incompatible for binary operator "+". The operand types could not be implicitly cast into compatible types for the operation. To perform this operation, one or both operands need to be explicitly cast with a cast operator.
Any help would be appreciated..
thanks,
ravi
Hi,
I have the same problem like Ben. Trying to connect to database engine but failed all the time. I use a SQL 2005 Enterprise Eval version. When I connect to database engine, I put <my computer name>SQLEXPRESS, it gives me this message:
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) (.Net SqlClient Data Provider)
I checked the sqlbrowser and it's running. I also enabled port 1434 in Firewall. But it still doesn't work. However, when I connect to analysis service using just <my computer name>, it lets me connected. I tried many ways to fix this problem but still no luck. Could anyone help me solve this problem please? Thanks so much.
Carl
Public Conn As New SqlConnection("Data Source=localhost;Initial Catalog=tblUsers;UID=XXXX;pwd=XXXX")Public Conn As New SqlConnection("Data Source=XX.XXX.XX.XXX;Initial Catalog=tblUsers;UID=XXXX;pwd=XXXX")
This two commands are in my application. I switch between the two so I can test my application.
When I put my application on the server, I use the localhost SQLCONNECTION. The other is commented out. However, the application continues to connect to the server with the address that is commented out.
THIS IS VERY FRUSTRATING... HELP!!!!
Hi, Someone can explain to me what happend in this situation...i have this and want to call a procedure with connection parameters protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection edo = new SqlConnection();
edo.ConnectionString = "server=myserver; uid=admin; pwd=; " +
"database=name1";
SqlCommand com = edo.CreateCommand();
com.CommandType = CommandType.Text;
My_proc(edo, com);
}
protected void My_proc(SqlConnection edo , SqlCommand com)
{
try
{edo.Open();
}
catch{}
finally{ edo.close();}
}
Well what happend with the SqlCommand and SqlConnection when return to Button_Click() Are they alive? Can be used in Buton_Click like parameters for another procedure? or i have to create it again?Thx in advance..
please help me !!!?I have a problem with sqlconnection definition when I add the sqlconnection from toolbox :like this: Imports System.Data.SqlClientPartial Class _Default Inherits System.Web.UI.Page Private Sub InitializeComponent() Me.sqlConnection1 = New System.Data.SqlClient.SqlConnection Me.sqlConnection1.ConnectionString = "Data Source=server;Initial Catalog=masterstd;User ID=sa" Me.sqlConnection1.FireInfoMessageEventOnUserErrors = False End Sub Private WithEvents sqlConnection1 As System.Data.SqlClient.SqlConnection Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then Dim cmduniversity As SqlCommand Dim dtruniversity As SqlDataReader cmduniversity = New SqlCommand("select * from university", sqlConnection1) sqlConnection1.Open() dtruniversity = cmduniversity.ExecuteReader dtruniversity.Close() sqlConnection1.Close() End If End SubEnd Classin the sqlconnection.open the nullrefrence exception occures butwhen i define myself this exception dosn't occure.like this: Imports System.Data.SqlClientPartial Class _Default Inherits System.Web.UI.Page Private Sub InitializeComponent() End Sub Private WithEvents sqlConnection1 As System.Data.SqlClient.SqlConnection Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then sqlConnection1 = New SqlConnection sqlConnection1.ConnectionString = "Data Source=server;Initial Catalog=masterstd;User ID=sa" sqlConnection1.FireInfoMessageEventOnUserErrors = False Dim cmduniversity As SqlCommand Dim dtruniversity As SqlDataReader cmduniversity = New SqlCommand("select * from university", sqlConnection1) sqlConnection1.Open() dtruniversity = cmduniversity.ExecuteReader dtruniversity.Close() sqlConnection1.Close() End If End Subwhere is the problem?
View 2 Replies View Related Can someone help me out? I am trying to establish a SQL server connection in my C# code. My C# code crasheds though. Can someone tell me what Iam doing wrong? Here is the C# code:
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["TheDividerConnectionString"]);
Here is the connection string as defined in the web.config file:
<connectionStrings> <add name="TheDividerConnectionString" connectionString="Data Source=BVCOMPUTERSQLEXPRESS;Initial Catalog=TheDivider;Integrated Security=True" providerName="System.Data.SqlClient" /> </connectionStrings>
is their any code which can check my project for any connections which are open and never closed.
frm 1.1,sql server 2000
Would anyone ahve any ideas why when i debug this code, it stops and freezes at cn.open(); A raw sql query against the DB works in this format.
int top=10;SqlConnection cn = new SqlConnection("Data Source=blah;Initial Catalog=blah;Integrated Security=blah");
SqlCommand cmd = new SqlCommand("SELECT DISTINCT TOP (@nrows) [CustNu] FROM [Customer] WHERE [CustNu] like @term", cn);cmd.Parameters.AddWithValue("nrows", top);cmd.Parameters.AddWithValue("term", prefixText + "%");
List <string> suggestions = new List<string>();
cn.Open();
HiI would like to have some help for my problem.I'm trying to retreive the connectionString "MyConnectionString" from app.config using method 1 or 2 to get a connection to my DB (without any success.) --> Partial codepublic SqlConnection GetConnection() { // reference to System.Configuration Library is done 1 SqlConnection Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString);--> thrown NullReferenceException on Conn.Open(); 2 SqlConnection Connection = new SqlConnection(ConfigurationSettings.AppSettings["MyConnectionString"]);--> thrown InvalidOperationException ConnectionString not initialised return Connection; } public Contest GetContestFromDB() { SqlConnection Conn = GetConnection(); Conn.Open(); ->> thrown Exception 1 or 2...Here my app.config :<?xml version="1.0" encoding="utf-8"?><configuration> <appSettings> <clear/> <add key="MyConnectionString" value="Server=.SQLExpress;AttachDbFilename=D:Documents and Settings0xMesdocumentsApp_DataShopperDB.MDF;Database=ShopperDB.MDF;Trusted_Connection=Yes;"></add> </appSettings> <connectionStrings> <clear/> --> using <clear/> to avoid to load from machine.config <add name="MyConnectionString" connectionString="Server=.SQLExpress;AttachDbFilename=D:Documents and Settings0xMes documentsApp_DataShopperDB.MDF;Database=ShopperDB.MDF;Trusted_Connection=Yes;"></add> </connectionStrings></configuration> I'm using Visual Studio 2008 with SQLServer 2005 Express Embedded and WindowsXP SP2 .Have you got any idea ?I'm not able to sleep anymore...And I've test this code in ASP.net with the same ConnectionString in the web.config file and it works !!I'm lost.By the way, thx if ou get an answer ww4ss
View 2 Replies View RelatedHi
I have the next simple code, what do i have to change to match it to SQL?
The code:
Sub Page_Load (Source As Object, E as EventArgs)
dim strConn as string =("Provider=" & "Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =C:webspacesegolforferaforfera.co.ildbguestbook.mdb")
Dim MySQL as string = "SELECT Name, EMail, URL, Comment FROM Guestbook"
Dim MyConn as New OleDBConnection (strConn)
Dim Cmd as New OleDBCommand (MySQL, MyConn)
MyConn.Open ()
rptGuestbook.DataSource = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
rptGuestbook.DataBind()
End Sub
Thank's and have a good day.
i am using visual web developer 2005 and SQL 2005 with VB as the code behindi am using INSERT command like this Dim test As New SqlDataSource() test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString1").ToString() test.InsertCommandType = SqlDataSourceCommandType.Text test.InsertCommand = "INSERT INTO try (roll,name, age, email) VALUES (@roll,@name, @age, @email) " test.InsertParameters.Add("roll", TextBox1.Text) test.InsertParameters.Add("name", TextBox2.Text) test.InsertParameters.Add("age", TextBox3.Text) test.InsertParameters.Add("email", TextBox4.Text) test.Insert() i am using UPDATE command like this Dim test As New SqlDataSource() test.ConnectionString = ConfigurationManager.ConnectionStrings("DatabaseConnectionString").ToString() test.UpdateCommandType = SqlDataSourceCommandType.Text test.UpdateCommand = "UPDATE try SET name = '" + myname + "' , age = '" + myage + "' , email = '" + myemail + "' WHERE roll 123 " test.Update()but i have to use the SELECT command like this which is completely different from INSERT and UPDATE commands Dim tblData As New Data.DataTable() Dim conn As New Data.SqlClient.SqlConnection("Data Source=.SQLEXPRESS;AttachDbFilename=|DataDirectory|Database.mdf;Integrated Security=True;User Instance=True") Dim Command As New Data.SqlClient.SqlCommand("SELECT * FROM try WHERE age = '100' ", conn) Dim da As New Data.SqlClient.SqlDataAdapter(Command) da.Fill(tblData) conn.Close() TextBox4.Text = tblData.Rows(1).Item("name").ToString() TextBox5.Text = tblData.Rows(1).Item("age").ToString() TextBox6.Text = tblData.Rows(1).Item("email").ToString() for INSERT and UPDATE commands defining the command,commandtype and connectionstring is samebut for the SELECT command it is completely different. why ?can i define the command,commandtype and connectionstring for SELECT command similar to INSERT and UPDATE ?if its possible how to do ?please help me
View 2 Replies View RelatedHi All,
i am using a OLE DB Source in my dataflow component and want to select rows from the source based on the Name I enter during execution time. I have created two variables,
enterName - String packageLevel (will store the name I enter)
myVar - String packageLevel. (to store the query)
I am assigning this query to the myVar variable, "Select * from db.Users where (UsrName = " + @[User::enterName] + " )"
Now in the OLE Db source, I have selected as Sql Command from Variable, and I am getting the variable, enterName,. I select that and when I click on OK am getting this error.
Error at Data Flow Task [OLE DB Source [1]]: An OLE DB error has occurred. Error code: 0x80040E0C.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E0C Description: "Command text was not set for the command object.".
Can Someone guide me whr am going wrong?
myVar variable, i have set the ExecuteAsExpression Property to true too.
Please let me know where am going wrong?
Thanks in advance.
I have a database for each of my customers and want to connect to a database depending on who is logged in.
all my users have their database name in the user profile.
how can i use the database name in the user profile to change the initial catalog to connect to aaother database?
thanks
Hi there, I'm not sure if the way I handle SqlConnection in my apps is the most performant one.So my apps use db heavily and there are loads of classes with methods like 1 using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConn"].ConnectionString))
2
3 {conn.Open();
4 // more code here
5 }
6
7
As I use using the connection is closed and the object is disposed when leaving the code block.I know that the connection is taken from a pool and when closed it returns to the pool as though I'm not sure if it is better to have one "global" SqlConnection objectand to use that object for all classes or most of them. What about the ConfigurationManager, doesn't it slow down the performance as well when I'm accessing the ConnectionString value thousands of times?I hope someone can point out the issues.Many thanks in advance, Limbic
I need some information on sqlconnnection object. I see it referenced in some exercises, and also displayed in the toolbox on some articles, but I'm running .net 2.0 and I have no sqlconnection in my toolbox, but more importantly, I can not seem to drop the data connection from my database/server explorer to my form to create a sqlconn object. When I highlight the data connection (in my case it's machinenamesqlexpress.pubs.dbo) and try to drag it - it immediately goes to a NO icon (that is a circle with a slash thru it) and I can not drop it onto my form. I can see the database with no problems in explorer.
I have been able to create a sqlconnection programatically:
Dim sqldatasource1 As SqlConnection = New SqlConnection()
sqldatasource1.ConnectionString = "Data Source=localhostsqlexpress;Initial Catalog=pubs;Integrated Security=True"
but how can I create it on my form?? I would appreciate any help on this matter.
(p.s. I am using VWD 2005 and SQLExpress)
I have created an aspx page that uses the SqlConnection class to pull data from Microsoft CRM’s database, and we have placed this aspx inside CRM’s directory on the server so that it uses the same integrated security that CRM uses. This works fine on our test environment but on our live environment the Sql connection fails with the exception: "Not associated with a trusted SQL Server connection"
This is probably because our test CRM server has the database on the same machine as the web server, but the live environment has the database and the web server on separate machines.
So my question is how can I create an aspx page that takes the integrated security credentials that the user used to log into the website and uses them to access data from a database on a seperate machine?
Hi,When using the following controls....System.Data.SqlClient.SqlConnection System.Data.SqlClient.SqlCommandIf I want to change my SQL command and execute the query once again what cleanup do I need to do first?Do I need close and dispose the SqlConnection?Do I need to dispose the SqlCommand?Can I use the SqlConnection for more than one SqlCommand?Thanks,Scott
View 5 Replies View RelatedI am working on a set of webforms that insert user data into a set of db tables.
I set up a test of an approach using northwind and I'm having trouble getting the insert to work. When I open the form, input the name and phone, and submit there is no error, but no record inserted into the Shippers table.
You can see one of my approaches in the ASPX code. I don't like having to do the select in order to do the insert -- so that's commented off.
I'm stuck. Thoughts about what I'm missing appreciated...
Ray
ASPX code.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default66a.aspx.cs" Inherits="pages_audit_Default66a" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server"><title>Untitled Page</title>
</head><body>
<form id="form1" runat="server">
CompanyName:
<asp:textbox id="txtCompanyName" runat="server" /><br />
Phone:<asp:textbox id="txtPhone" runat="server" /><br />
<br />
<asp:button id="btnSubmit" runat="server" text="Submit" onclick="btnSubmit_Click" />
<br />
<br />
<br />
<br />
<asp:Label ID="awesomelbl" runat="server" Text="Label"></asp:Label><br />
<br />
<!--
<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:NorthwindConnectionString %>"
insertcommand="INSERT INTO Shippers(CompanyName, Phone) VALUES (@CompanyName, @Phone)" ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM [Shippers]">
<insertparameters>
<asp:controlparameter controlid="txtCompanyName" name="CompanyName" />
<asp:controlparameter controlid="txtPhone" name="Phone" />
</insertparameters>
</asp:sqldatasource>
--></form>
</body>
</html>
c Sharp code
using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.Sql;
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;
public partial class pages_audit_Default66a : System.Web.UI.Page
{protected void Page_Load(object sender, EventArgs e)
{
}protected void btnSubmit_Click(object sender, EventArgs e)
{SqlConnection con = new SqlConnection("Data Source=Chilibowl;Trusted_Connection=yes;DataBase=Northwind");
SqlCommand cmd = new SqlCommand("INSERT INTO [Shippers] ([CompanyName], [Phone]) VALUES (@CompanyName, @Phone)");SqlParameter cnameparam = new SqlParameter("@CompanyName", txtCompanyName.Text); SqlParameter phnparam = new SqlParameter("@Phone", txtPhone.Text);
cmd.Parameters.Add(cnameparam);
cmd.Parameters.Add(phnparam);
try
{
con.Open();if (cmd.ExecuteNonQuery() > 0)awesomelbl.Text = "successful insert";
}
catch
{
//handel
}
finally
{
con.Close();
}
}
}