hi frnds,
i want to know, can we pass sqlcommand object to sql dataadapter.
please let me know,
Thanks,
aamir
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
sujit bistaPosted Jan 8, 2013, 1:34 AM
Public Class Form1
'Dim sq As SqlCommandBuilder
Dim adp As SqlDataAdapter
Function RetDataTable() As DataTable
Dim dt As New DataTable
Dim _Connection As New SqlConnection("Server=mac-dols;UID=sa;PWD=macdols12;Database=db1")
Dim com As New SqlCommand()
com.CommandType = CommandType.StoredProcedure
com.CommandText = "procname"
com.Connection = _Connection
com.Parameters.AddWithValue("@count", "2")
adp = New SqlDataAdapter(com)
' sq = New SqlCommandBuilder(adp)
adp.Fill(dt)
Return dt
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.DataSource = RetDataTable()
End Sub
End Class
Satyapriya NayakPosted Sep 30, 2011, 9:59 AM
using System.Data;
using System.Data.SqlClient;
SqlConnection con=new SqlConnection("server=localhost;uid=sa;pwd=;database=std");
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
private void btnload_Click(object sender, System.EventArgs e)
{
con.Open();
str="select * from student";
com=new SqlCommand(str,con);
sqlda=new SqlDataAdapter(com);
ds=new DataSet();
sqlda.Fill(ds,"student");
dataGrid1.DataSource=ds;
dataGrid1.DataMember=("student");
con.Close();
}
Thanks
Pravin MorePosted Sep 30, 2011, 8:39 AM
do it like this..........
SqlConnection con1 = new SqlConnection("Data Source=xxxx;Initial Catalog=xxxx;Persist Security Info=True;User ID=xxxxx;Password=*****");
SqlCommand cmd1 = new SqlCommand("Select * from TableName", con1);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
Thanx,Hope this solve your problem.
Pravin.