Keyword not supported: 'datasource'.

The code behind for a button click is as below:
protected void Button1_Click(object sender, EventArgs e)
{
obj.connect();
obj.cmd.Parameters.Add("@ID",SqlDbType.Int).Value=TextBox1.Text;
obj.cmd.Parameters.Add("@Password", SqlDbType.VarChar).Value = TextBox2.Text;
obj.cmd.Parameters.Add("@ConfirmPassword", SqlDbType.VarChar).Value = TextBox3.Text;
obj.cmd.Parameters.Add("@Email", SqlDbType.VarChar).Value = TextBox4.Text;
obj.cmd = new SqlCommand("submitrecord");
obj.cmd.ExecuteNonQuery();
obj.db.Close();
Label l1 = new Label();
l1.Text = "Record has been submitted!";
}
Savita JoshiPosted Apr 5, 2011, 8:41 AM
r u not comfortable using vb.net? OK i will convert the class to c# and upload. Just syntax is slightly different right!!!!!!!
Vijay YadavPosted Apr 5, 2011, 6:03 AM
Just try this:
Dim con As New SqlConnection
Dim cmd As New SQlCommand
Con.ConnectionString="Data Source=;Initial Catalog=;Integrated Security=True"
con.Open()
cmd.CommandText = "INSERT into tblCustomer(title, firstname) Values (" & title & " , " & firstname & ")"
cmd.Connection=con
cmd.ExecuteNonQuery()
con.Close()
Krishna GaradPosted Apr 5, 2011, 5:59 AM
Savita JoshiPosted Apr 5, 2011, 5:41 AM
I dont think it has to do anything with the connection class ,anyways will upload it check it
Krishna GaradPosted Apr 5, 2011, 12:21 AM
why not it best to upload your connection.cs file here? Then we can check it.
Blocked AccountPosted Apr 5, 2011, 12:15 AM
just attach your code here.
Savita JoshiPosted Apr 4, 2011, 9:01 PM
I checked it the way u said but the problem is still there..
ie
ExecuteNonQuery: Connection property has not been initialized.I am getting this error now.. Please help
Suthish NairPosted Apr 4, 2011, 9:44 AM
We trying to help you, but you not trying to help yourself.
Put breakpoint debug each line and check where its getting failed.
After obj.connect(), check your connection is working or not.
For example:
using (SqlConnection con = new SqlConnection())
{
if (con.State == ConnectionState.Open) { }
}
Savita JoshiPosted Apr 4, 2011, 7:18 AM
If u check the above posts i have written the connection class(ie i have separate class for connection who`s object i create and use it in all pages) and used it where all want it..
Suthish NairPosted Apr 1, 2011, 4:29 AM
First of all there is no connection opened for you logic to work.
how to find actual connection string
Find Database Connection and Generate Connection String using Visual Studio
this article help how to use connection and command.
DataGridView - Insert, Update, Delete and Retrieve records using stored procedure
Krishna GaradPosted Apr 1, 2011, 3:35 AM
public static void ExecuteCommand(string _command, SqlParameter[]Param)
{
try
{
cn.Open();
cmd = new SqlCommand(_command, cn);
foreach (SqlParameter p in Param)
{
cmd.Parameters.Add(p);
}
cmd.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
cn.Close();
}
}
wirte the code in your button_click event like bellow
Connection.Connect();
SqlParameter[] Param=new SqlParameter[4];//Size is variable depends on requirement.
Param[0]=new SqlParameter(""@ID",SqlDbType.Int");
Param[0].Value=TextBox1.Text;
// Create all parameter with value and now call ExecuteCommand Method
Connection.ExecuteCommand("Sql Statement",Param);//Write Insert Query insted of Sql Statement here.
Mayur GujrathiPosted Apr 1, 2011, 3:21 AM
Krishna GaradPosted Apr 1, 2011, 3:19 AM
Savita JoshiPosted Apr 1, 2011, 3:15 AM
Earlier tried the same way but its still not working..
It gives the error i mentioned
ExecuteNonQuery: Connection property has not been initialized.I am getting this error now
Krishna GaradPosted Apr 1, 2011, 3:09 AM
public static class Connection
{
static SqlConnection cn;
static SqlCommand cmd;
static SqlDataReader dr;
public static void Connect()
{
string connstring = "Data source=SHRINIVAS;Initial Catalog=test;Integrated security=true";
cn = new SqlConnection(connstring);
cn.Open();
}
//write seperate method for command object like above
public static void Command(string _sql)
{
//implement for command
}
}
Savita JoshiPosted Apr 1, 2011, 2:56 AM
THIS IS THE CONNECTION CLASS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
///
/// Summary description for data
///
public class data
{
public SqlConnection db;
public SqlCommand cmd;
public SqlDataReader dtr;
public string str;
public data()
{
//
// TODO: Add constructor logic here
//
}
public void connect()
{
str = "Data source=test;Initial Catalog=test;Integrated security=true";
db = new SqlConnection(str);
db.Open();
cmd = new SqlCommand("", db);
}
}
Krishna GaradPosted Apr 1, 2011, 2:47 AM
Savita JoshiPosted Apr 1, 2011, 2:42 AM
I have declared db,cmd which are sqlconnection object and sqlcommand object respectively outside the connect method using public modifier..
Krishna GaradPosted Apr 1, 2011, 2:21 AM
Public void connect()
{
string str="Data source=om;initial catalog=test;integrated security=true";
SqlConnection cn=new SqlConnection(str);//here was the error.
cn.Open()
//cmd=new sqlcommand("",db);
}
Savita JoshiPosted Apr 1, 2011, 2:17 AM
ExecuteNonQuery: Connection property has not been initialized.I am getting this error now.. Please help
@Krishna,
Public sqlconnection db;
Public sqlcommand cmd;
Public void connect()
{
string str="Data source=om;initial catalog=test;integrated security=true";
db=new sqlconnection(str);
db.open();
cmd=new sqlcommand("",db);
}
This is the connect method...
Krishna GaradPosted Mar 30, 2011, 2:19 AM
connect()
{
SqlConnection conn=new SqlConnection("ConnectionString");
}
Savita JoshiPosted Mar 30, 2011, 2:16 AM
I have created stored procedure... Is that code correct????
i am still getting this error now:
ExecuteNonQuery: Connection property has not been initialized
Krishna GaradPosted Mar 30, 2011, 2:07 AM
"Data source=om;Initial Catalog=student;Integrated security=true";
Check what I've done change in your original connection string.
Savita JoshiPosted Mar 30, 2011, 2:04 AM
Krishna GaradPosted Mar 30, 2011, 2:01 AM
Savita JoshiPosted Mar 30, 2011, 2:00 AM
really did not get wat u r speaking!!!!!!!!!!!!!
Krishna GaradPosted Mar 30, 2011, 1:56 AM
Savita JoshiPosted Mar 30, 2011, 1:54 AM
I have a separate connection class.. I am creating object obj of that connection class and using its method to connect to database..
Krishna GaradPosted Mar 30, 2011, 1:49 AM
"Data Source=servername;user id=;password=;Database=DB"