Tuesday, December 21, 2010
asp.net and sql server
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Load all" />
</form>
</body>
web.config
<appSettings>
<add key="localhost" value="dbConnectionString"/>
</appSettings>
<connectionStrings>
<add name="dbConnectionString" connectionString="Data Source=.\SQLEXPRESS; User ID=sa; Password=pswd; Database=testdatas; TimeOut=1 " providerName="System.Data.SqlClient"/>
</connectionStrings>
aspx page.cs
public partial class _Default : System.Web.UI.Page
{
SqlConnection sqlcon;
SqlCommand SqlCmd;
string ConnectionName = "";
string ConnectionString = "";
SqlDataReader SqlDr;
List<string> LstString;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Response.Write(DateTime.Now.ToString());
}
}
protected void Button1_Click(object sender, EventArgs e)
{
ConnectionName = ConfigurationManager.AppSettings["localhost"].ToString();
ConnectionString = ConfigurationManager.ConnectionStrings[ConnectionName].ToString();
sqlcon = new SqlConnection();
SqlCmd = new SqlCommand();
sqlcon.ConnectionString = ConnectionString;
SqlCmd.CommandText = "insert into tbone (name) values (@users)";
SqlCmd.Parameters.AddWithValue("@users",TextBox1.Text);
SqlCmd.Connection = sqlcon;
sqlcon.Open();
SqlCmd.ExecuteNonQuery();
sqlcon.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
ConnectionName = ConfigurationManager.AppSettings["localhost"].ToString();
ConnectionString = ConfigurationManager.ConnectionStrings[ConnectionName].ToString();
sqlcon = new SqlConnection();
SqlCmd = new SqlCommand();
LstString = new List<string>();
sqlcon.ConnectionString = ConnectionString;
SqlCmd.CommandText = "select * from tbone";
SqlCmd.Parameters.AddWithValue("@users", TextBox1.Text);
SqlCmd.Connection = sqlcon;
sqlcon.Open();
SqlDr = SqlCmd.ExecuteReader();
while (SqlDr.Read())
{
LstString.Add(SqlDr["name"].ToString());
}
SqlDr.Close();
sqlcon.Close();
DropDownList1.DataSource = LstString;
DropDownList1.DataBind();
}
}
Tuesday, June 22, 2010
connect silverlight with ms sql server
2. Check the checkbox to host the silverlight application in a new web application “silverlight_wcf_sql.Web”
3. Silverlight page design
4. Add a new WCF Service and name it sql_wcf.svc
5. Add a method say “GetName()” like
[OperationContract]
public string GetName()
{
//refer attached file
}
OperationContract attribute above the method name indicates that this method can be called from a WCF client.
- Refer the sample project attached.
7. Go to MainPage.xaml and double click the button to generate BtnClickMe_Click event and type the code
private void BtnClickMe_Click(object sender, RoutedEventArgs e)
{
BtnClickMe.IsEnabled = false;
Silverlight_wcf_service_reference.sql_wcfClient myclient = new Silverlight_wcf_service_reference.sql_wcfClient();
myclient.GetNameCompleted += new EventHandler
myclient.GetNameAsync();
txtBlkSQL.Text = "Receiving data...";
LbMessage.Content = "http://www.rodriguesjax.blogspot.com";
}
void myclient_GetNameCompleted(object sender, Silverlight_wcf_service_reference.GetNameCompletedEventArgs e)
{
txtBlkSQL.Text = (string)e.Result;
BtnClickMe.IsEnabled = true;
}
Click here to download silverlight_wcf_sql.rar
use visual studio 2010
Wednesday, June 9, 2010
Getting started silverlight
- Open Visual Studio and Click File->New Project… And Select Silverlight Application in Silverlight Templates. You can give a name to the project say MyFirstApplication and click OK.
- This is to select whether you need to add a web application in the solution to host the silverlight file(xap). This is optional depending upon your requirement. This is similar to adding projects to a solution.
- Drag and drop a Button and TextBlock control from the ToolBox in MainPage.xaml. You may adjust the width of TextBlock. Then double click the button to go to the ‘button1_Click’ event in the code file(MainPage.xaml.cs). You may be able to see other available events for the control in the Events tab in Properties window. Double click a event to go to the particular event.
private void button1_Click(object sender, RoutedEventArgs e)
{
textBlock1.Text = "Hello, Welcome to silverlight";
}
- Press F5 to start debugging the silverlight application.
Click here to download the sample file
Share it
Saturday, May 15, 2010
Asp.net MultiView
A multiview is useful when data from one page need to be transferred to another page. Example to jump from one page to other in a shopping cart web site. For each page step of shopping each views in MultiView can be used. MultiView control shows only one view at a time. So the same page seems to more than one page depending upon number of views present inside a multiview.
To use a MultiView control just drag and drop a MultiView control from the toolbox. Then add views from the toolbox in the blank area the MultiView control. Add more views by drag and dropping the view control on the grey header of previously added view control.
E.g.:
WebForm1.aspx
<asp:Button ID="Button1" runat="server" Text="General"
onclick="Button1_Click" />
<asp:MultiView ID="MultiView1" runat="server">
<asp:View ID="View2" runat="server">
View Two
</asp:View>
<asp:View ID="View1" runat="server">
View One
</asp:View>
</asp:MultiView>
To view the contents inside a view say View1 when Button1 is clicked use the following code.
protected void Button1_Click(object sender, EventArgs e)
{
MultiView1.SetActiveView(View1);
}
Monday, April 5, 2010
Kerala Google Technology User Group Launch
Trivandrum, India
http://www.kerala-gtug.org/30/launch-event/
Tuesday, March 9, 2010
Rss2.0 And Atom1.0 Compared
RSS and Atom
People who generate syndication feeds have a choice of feed formats. As of mid-2005, the two most likely candidates will behttp://www.intertwingly.net/wiki/pie/Rss20AndAtom10Compared