detail code for sql data connections?
Answers were Sorted based on User's Feedback
Answer / nitin kumar
Steps for 1. Using a SqlConnection
// Fully Commented Code
using System;
using System.Data;
using System.Data.SqlClient;
class SqlConnectionDemo
{
static void Main()
{
// 1. Instantiate the connection
SqlConnection conn = new SqlConnection(
"Data Source=(local);Initial
Catalog=Northwind;Integrated Security=SSPI");
SqlDataReader rdr = null;
try
{
// 2. Open the connection
conn.Open();
// 3. Pass the connection to a command object
SqlCommand cmd = new SqlCommand("select * from
Customers", conn);
//
// 4. Use the connection
//
// get query results
rdr = cmd.ExecuteReader();
// print the CustomerID of each record
while (rdr.Read())
{
Console.WriteLine(rdr[0]);
}
}
finally
{
// close the reader
if (rdr != null)
{
rdr.Close();
}
// 5. Close the connection
if (conn != null)
{
conn.Close();
}
}
}
}
Is This Answer Correct ? | 7 Yes | 0 No |
Answer / bhagwat prasad sharma
Steps: SqlConnection with vb.net code
'' Code
imports system.data.sqlclients
Public Class Form1 Inherits System.Windows.Forms.Form
'' createconnection with database
dim con as new sqlconnection("server=bps; database=company; user id=sa; password=admin")
private sub button1_click()
dim str as string="insert into employee (roll_no,name,class) values(@roll_no,@name,@class)"
dim cmd as new sqlcommand =(str,con)
if con.state=connectionstate.closed than
con.open()
'' parameter passing
cmd.parameters.add("@roll_no",type.int)
cmd.parameters.add("@name",type.varchar)
cmd.parameters.add("@class",type.varchar)
cmd.parameters("@roll_no").value= txtroll.text
cmd.parameters("@name").value=txtname.text
cmd.parameters("@class").value= txtclass.text
dim i as integer
i=cmd.executeNonquery
if i>o
msgbox("addition successful")
else
msgbox("sum mistakes into add")
end if
' end of connection
con.close()
end sub
end class
Is This Answer Correct ? | 2 Yes | 1 No |
Explain Assemblies?,Difference between Panel and GroupBox?,Differences between ASP and ASP.NET?
If we add a textbox and give the required field validator,and i add two radio buttons 1 is yes another one is No.And i add another one server control button ,if i click the button ,if the radio button Yes is checked the validation control is fired ,if no the validation control is not fired.So what you used to solve this problem.
What is marshalling ? Is it a part of asp.net ?
How does the service stream content?
What are the types of session in asp.net?
About Windows/Forms Authentication
what is client back feauture ?
How to use class library reference in asp.net project? Can you give me the example with source Class library haves classes like Database, insert, update, delete, reflection how can i use the database class connection in insert class to insert the record in to the Main Project in asp.net.
there is two functions function a and function b like fun a(){.... ..... } fun b() { } in function b i write the coding to add two numbers and i need to dispaly the sum result in function a with out using global variable. how we do?
How many time you can fill dataset in asp.net?
How can we apply themes to an asp.net application?
How can we create Tree control in asp.net?