SQL Server 2005 - asp.net

i created one ASP.Net project using SQL Server 2005 .I successfully inserted .But i dont know to view the table.Please tell me

A beginner instrudciton into SQL server seems in order - you seem to stumble around not knowing anything about hwat you really deal with.
I suggest heading over to ASP.NET (http://www.asp.net/) and read the indroduction documentation, as well as have some look at the sample code and the beginner forum.

Well this is a pretty broad question, but to get data into a datatable you could do something like:
DataTable dt = new DataTable();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLConnection"].ConnectionString);
SqlCommand cmd = new SqlCommand("Retrieve", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("#ID", SqlDbType.Int).Value = ID;
SqlDataAdapter sqldata = new SqlDataAdapter(cmd);
con.Open();
sqldata.Fill(dt);
con.Close();

Related

Can Glimpse provide diagnostics when using the SqlClient namespace classes

I've downloaded Glimpse and the Glimpse.ADO extension and installed it on my test instance.
I thought I'd get a capture of any sql that was executed, but it seems like it doesn't capture commands with the way our code is written.
using (var conn = new SqlConnection(cString))
{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "Select count(*) from table";
cmd.CommandType = CommandType.Text;
txtResult2.Text = cmd.ExecuteScalar().ToString();
conn.Close();
}
I CAN get it to provide information from a test page with the sql code written like so:
var factory =DbProviderFactories.GetFactory(cString.ProviderName);
using (var connection = factory.CreateConnection())
{
connection.ConnectionString = connectionString.ConnectionString;
connection.Open();
using (var command = connection.CreateCommand())
{
command.CommandText = "SELECT COUNT(*) FROM table";
command.CommandType = CommandType.Text;
txtResult1.Text = command.ExecuteScalar().ToString();
}
}
However I have too many places in my code to change if I can only capture data using this dbProviderFactories method.
Is there a way to get Glimpse.ADO to work with the System.Data.SqlClient.SqlConnection class? Is there another Glimpse extension that works with this namespace?
Is there another way to tackle this problem?
I agree with #StriplingWarrior, leveraging the provider factories will make your code more DRY and follow best practices. DbProviderFactories really is the best way to do this and your code won't explicitly rely on Glimpse.
However, if you really want to just move forward with your existing app code, Glimpse will support you with the following changes:
using (var conn = new GlimpseDbConnection(new SqlConnection(cString))
{
conn.Open();
DbCommand cmd = conn.CreateCommand();
cmd.CommandText = "Select count(*) from table";
cmd.CommandType = CommandType.Text;
txtResult2.Text = cmd.ExecuteScalar().ToString();
conn.Close();
}
In the example above, the command is created with the CreateCommand() method, which removes the need to associate the command and the connection.
Alternatively, you could also still explicitly create the command like so:
conn.Open();
DbCommand cmd = new GlimpseDbCommand(new SqlCommand());
cmd.Connection = conn;
cmd.CommandText = "Select count(*) from table";
cmd.CommandType = CommandType.Text;
Finally, more documentation about the SQL tab is available by clicking the ? icon in the Glimpse UI when you have the tab selected, or by going to our SQL documentation on getGlimpse.com. (I'll be adding this info to that page for future reference.)
In problems section on Glimpse site...
Getting Glimpse to work with manual created SQL Connections/Commands
http://getglimpse.com/Docs/Manual-ADO-Integration

Can't see parameters using dataset with crystal reports

I've been dealing with this problem for more than 6 months, when I create a dataset and inside de dataset I call a stored procedure and then call this dataset into my report (crystal reports) I can't see the parameter fields:
I try to create the parameters in a sqlcommand and then add the parameters to my report using
rpt.setParameters("#a","sample");
but I got an error.
What could I do? please help me, I'm very desperated and angustied with this
My code (Sorry if it's in spanish) :
Dim cmd As New SqlCommand("prd_generarReporteOP", cn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add("#idop", SqlDbType.Int).Value = CInt(Session("idop"))
cmd.Parameters.Add("#producto", SqlDbType.VarChar).Value = ""
Dim da As New SqlDataAdapter da.SelectCommand = cmd
Dim ds As New DataSetOP da.Fill(ds, "DataSetOP")
You need to change your data source. Since you using the the dataset as the datasource you already getting the filtered results.
You need to use the stored-procedure as your data source and then the parameters will appear

Crystal Reports and strongly typed datasets yields empty report

I am converting an ASP.Net app from VS 2003 to VS 2005 as a starting point. The app uses Crystal Reports and binds using ADO.Net to a strongly typed dataset (XSD). I had to change some of Crystal Code to work with the newer version of Crystal. Now, when I run the page, the report generates, but none of the fields fill in. I have seen lots of people having the same problem with no real solutions out there. I decided to create a fresh project that does the same thing to remove the conversation from VS 2003 to 2005 as a possible cause of the problem. So my sample program has a button that runs a query, fills the dataset and assigns it to the report. The report displays the headers only. The code is below. I have no idea what to try next.
DataSet1 ds = new DataSet1();
SqlConnection conn =
new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter("select * from mytable", conn);
da.Fill(ds);
ReportDocument rep = new ReportDocument();
rep.Load(Server.MapPath("crystalreport.rpt"));
rep.SetDataSource(ds);
CrystalReportViewer1.ReportSource = rep;
CrystalReportViewer1.RefreshReport();
I also created the DataSet1.XSD based on the same MYTABLE table. I get no errors or any indication anything is wrong except that the fields in the report don't populate.
It would take some debugging to know for sure why it's not working for you. Have you looked at the resulting dataset in a debugging session, and seen if it fills correctly?
Here's a good example of a method to work from.
SqlConnection cnn;
string connectionString = null;
string sql = null;
connectionString = "data source=SERVERNAME;initial catalog=DATABASENAME;user id=USERNAME;password=PASSWORD;";
cnn = new SqlConnection(connectionString);
cnn.Open();
sql = "select * from mytable";
SqlDataAdapter dscmd = new SqlDataAdapter(sql, cnn);
DataSet1 ds = new DataSet1();
dscmd.Fill(ds, "mytable");
cnn.Close();
CrystalReport1 objRpt = new CrystalReport1();
objRpt.SetDataSource(ds.Tables[1]);
crystalReportViewer1.ReportSource = objRpt;
crystalReportViewer1.Refresh();

Binding Data from A Dataset to a <asp:Table>

Here I got slapped by a nice Surprise! <asp:Table> has no DataSource property. So far I have this code.
System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Careers"].ConnectionString);
conn.Open();
System.Data.SqlClient.SqlCommand comm = new System.Data.SqlClient.SqlCommand("SELECT * FROM Careers", conn);
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(comm);
System.Data.DataSet ds = new System.Data.DataSet();
da.Fill(ds);
System.Data.DataTable dt = ds.Tables[0];
//tbVCareers.IMAGINARYDATASOURCE = dt;
tbVCareers.DataBind();
This is only a testpage I am writing , so the Table is not supposed to look pretty. How am I to bind Data to this table? Note, this is not the same database connection that I posted in an earlier question. Any insight someone can Lend to me?
<asp:Table> is not data control, so you cannot do that with <asp:Table>. you have to use <asp:GridView>

error in mysql connection "The given key was not present in the dictionary"

I have problem while connecting to mysql database using "ADO.NET Driver for MySQL (Connector/NET)"
I got this exception The given key was not present in the dictionary.
Edit:
MySqlConnection con = new MySqlConnection("Server=localhost;Database=pgs_db;Uid=root;Pwd=;");
MySqlCommand com = new MySqlCommand();
com.CommandType = CommandType.StoredProcedure;
com.Connection = con;
com.CommandText = "getStudent";
con.Open();
MySqlDataReader dr =com.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
con.Close();
sorry i was using a worng connectionstring
this is a right one :
"server=localhost; user id=user; password=password; database=mydatabase; pooling=false;"
thnx Oded
Without seeing the code, I am guessing you are trying to access a configuration key that does not exist in your application config file.
Edit:
After seeing the code sample, the problem is probably not with connecting to the DB.
I would say that in your GridView, you are binding to a field that is not returned by the DB query.

Resources