|
Hi
I am writing the Blog on this because i have face the problem on such question i have search in Google also but i could not find such answer which was related to my query.
Well the query i was face is i want to print the data on label by the selection from drop down list.
For Example : There is one table call Product and Second table called Discount there is no relationship between this two table then also i want on the selection of the product i should get a discount to be printed in label.
So the code for this type of query is :-
private void combobox_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection cnn1 = new SqlConnection(@"");
cnn1.Open();
DataSet da = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter("select * from table you want", cnn1);
sda.Fill(da, "Tablename");
int i = 0;
for (i = 0; i <= da.Tables["tablename"].Columns.Count - 1; i++)
{
string strcolumn = da.Tables[0].Columns[i].ToString();
string strvalue = da.Tables[0].Rows[0][i].ToString();
if (combobox.SelectedItem.ToString() == "columnname")
{
if (combobox.SelectedItem.ToString() == strcolumn)
{
label5.Text = strvalue;
}
}
else
{
if (combobox.SelectedItem.ToString() == "columnname")
{
if (combobox.SelectedItem.ToString() == strcolumn)
{
label5.Text = strvalue;
}
}
Happy Coding 
|
|
|
|
|
protected void btnlogin_Click(object sender, EventArgs e)
{
SqlConnection cnn = new SqlConnection();
cnn.ConnectionString = "Your connection";
cnn.Open();
SqlCommand cmd = new SqlCommand("select mobileno, password from register where mobileno='"+txtmoblie.Text +"'and password='"+txtpassword.Text+"'",cnn);
cmd.Connection = cnn;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Response.Redirect("http://www.google.com");
}
else
{
Response.Write(@"<script language='javascript'>alert('Invalid Username and Password')</script>");
}
cnn.Close();
}
Happy coding 
modified 12-Dec-11 23:50pm.
|
|
|
|
|
Hi
This code is basically for storing the data from datagridview to sql server
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace MIC
public Form1()
{
InitializeComponent();
}
public SqlConnection getsqlcon()
{
string connstring = "Server Name";
SqlConnection con = new SqlConnection(connstring);
return con;
}
public bool getcomm(string connstring1)
{
try
{
SqlConnection sqlcon = this.getsqlcon();
SqlCommand sqlcomm = new SqlCommand(connstring1,sqlcon);
sqlcon.Open();
sqlcomm.ExecuteNonQuery();
sqlcomm.Dispose();
sqlcon.Close();
sqlcon.Dispose();
return true;
}
catch(Exception ex)
{
return false;
}
private void btnsubmit_Click(object sender, EventArgs e)
{
try
{
string col1 = dataGridView1[0, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col2 = dataGridView1[1, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col3 = dataGridView1[2, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string col4 = dataGridView1[3, dataGridView1.CurrentCell.RowIndex].Value.ToString();
string insert_sql = "insert into clientwiseproductwise(col1,col2,col3,col4)values('" + col1 + "','" + col2 + "','" + col3 + "','" + col4 + "')",con;
if (this.getcomm(insert_sql))
{
MessageBox.Show("Insert Success");
}
else
{
MessageBox.Show("Insert Failed");
}
}
catch
{
}
Happy coding 
|
|
|
|