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!";
}

Krishna GaradRank #191 · 12.8K reputationPosted Mar 29, 2011, 9:49 PM EDT
"Data Source=servername;user id=;password=;Database=DB"
Savita Joshi124 reputationPosted Mar 29, 2011, 9:54 PM EDT
I have a separate connection class.. I am creating object obj of that connection class and using its method to connect to database..
Krishna GaradRank #191 · 12.8K reputationPosted Mar 29, 2011, 9:56 PM EDT
Savita Joshi124 reputationPosted Mar 29, 2011, 10:00 PM EDT
really did not get wat u r speaking!!!!!!!!!!!!!
Krishna GaradRank #191 · 12.8K reputationPosted Mar 29, 2011, 10:01 PM EDT
Savita Joshi124 reputationPosted Mar 29, 2011, 10:04 PM EDT
Krishna GaradRank #191 · 12.8K reputationPosted Mar 29, 2011, 10:07 PM EDT
"Data source=om;Initial Catalog=student;Integrated security=true";
Check what I've done change in your original connection string.
Savita Joshi124 reputationPosted Mar 29, 2011, 10:16 PM EDT
I have created stored procedure... Is that code correct????
i am still getting this error now:
ExecuteNonQuery: Connection property has not been initialized
Krishna GaradRank #191 · 12.8K reputationPosted Mar 29, 2011, 10:19 PM EDT
connect()
{
SqlConnection conn=new SqlConnection("ConnectionString");
}
Savita Joshi124 reputationPosted Mar 31, 2011, 10:17 PM EDT
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 GaradRank #191 · 12.8K reputationPosted Mar 31, 2011, 10:21 PM EDT
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 Joshi124 reputationPosted Mar 31, 2011, 10:42 PM EDT
I have declared db,cmd which are sqlconnection object and sqlcommand object respectively outside the connect method using public modifier..
Krishna GaradRank #191 · 12.8K reputationPosted Mar 31, 2011, 10:47 PM EDT
Savita Joshi124 reputationPosted Mar 31, 2011, 10:56 PM EDT
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 GaradRank #191 · 12.8K reputationPosted Mar 31, 2011, 11:09 PM EDT
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 Joshi124 reputationPosted Mar 31, 2011, 11:15 PM EDT
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 GaradRank #191 · 12.8K reputationPosted Mar 31, 2011, 11:19 PM EDT
Mayur GujrathiRank #666 · 3.6K reputationPosted Mar 31, 2011, 11:21 PM EDT
Krishna GaradRank #191 · 12.8K reputationPosted Mar 31, 2011, 11:35 PM EDT
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.
Suthish NairRank #92 · 22.8K reputationPosted Apr 1, 2011, 12:29 AM EDT
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
Savita Joshi124 reputationPosted Apr 4, 2011, 3:18 AM EDT
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 NairRank #92 · 22.8K reputationPosted Apr 4, 2011, 5:44 AM EDT
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 Joshi124 reputationPosted Apr 4, 2011, 5:01 PM EDT
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
Blocked AccountRank #403 · 6.2K reputationPosted Apr 4, 2011, 8:15 PM EDT
just attach your code here.
Krishna GaradRank #191 · 12.8K reputationPosted Apr 4, 2011, 8:21 PM EDT
why not it best to upload your connection.cs file here? Then we can check it.
Savita Joshi124 reputationPosted Apr 5, 2011, 1:41 AM EDT
I dont think it has to do anything with the connection class ,anyways will upload it check it
Krishna GaradRank #191 · 12.8K reputationPosted Apr 5, 2011, 1:59 AM EDT
Vijay YadavRank #1,637 · 943 reputationPosted Apr 5, 2011, 2:03 AM EDT
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()
Savita Joshi124 reputationPosted Apr 5, 2011, 4:41 AM EDT
r u not comfortable using vb.net? OK i will convert the class to c# and upload. Just syntax is slightly different right!!!!!!!